protected override void OnStart(string[] args) { //----- Set Threads! ThreadPool.SetMinThreads(4, 4); ThreadPool.SetMaxThreads(32, 32); chatServer = new SocketServer(new ChatSocketService.ChatSocketService()); chatServer.Delimiter = new byte[] { 0xAA, 0xFF, 0xAA }; chatServer.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive; chatServer.SocketBufferSize = 1024; chatServer.MessageBufferSize = 512; //----- Socket Listener! SocketListener listener = chatServer.AddListener("Char Server", new IPEndPoint(IPAddress.Any, 8090)); listener.AcceptThreads = 3; listener.BackLog = 50; listener.CompressionType = CompressionType.ctNone; listener.EncryptType = EncryptType.etRijndael; listener.CryptoService = new ChatCryptService.ChatCryptService(); chatServer.Start(); }
//public void StarService(CompressionType eCompression, int iMaxClient, int iPort, int iSocketBuffer) public void StarService(IPEndPoint pEndPoint, CompressionType eCompression, int iSocketBuffer) { //IPEndPoint pServerPoint = new IPEndPoint(0, iPort); //pSocketServer = new SocketServer(this, eCompression, iSocketBuffer, 1, 1); //pSocketServer.AddListener(pServerPoint, iMaxClient); //pSocketServer.ServiceStart(); switch (this._eNetService) { case NetServiceType.HOST: pSocketServer = new SocketServer(this, eCompression, iSocketBuffer, this.iCheckInterval, this.iCheckTimeOut); pSocketServer.AddListener(pEndPoint, this.iMaxClient); pSocketServer.ServiceStart(); break; case NetServiceType.CLIENT: pSocketClient = new AsyncClient(this, eCompression, iSocketBuffer, this.iCheckInterval, this.iCheckTimeOut); pSocketClient.AddConnector(pEndPoint); pSocketClient.ServiceStart(); break; } }
protected override void OnStart(string[] args) { FEvent = new OnEventDelegate(Event); FEchoLog = new StreamWriter(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\EchoLog.txt"); FServer = new SocketServer(new EchoSocketService.EchoSocketService(FEvent), DelimiterType.dtMessageTailExcludeOnReceive, Encoding.GetEncoding(1252).GetBytes("ALAZ"), 1024 * 2, 1024 * 16); FServer.AddListener("Commom Port - 8090", new IPEndPoint(IPAddress.Any, 8090), EncryptType.etRijndael, CompressionType.ctNone, new EchoCryptService.EchoCryptService(), 50, 3); FServer.Start(); }
/// <summary> /// Starts the virtualized service. When used as Virtual Server, the service will registers TCP port and services descriptions. /// </summary> public override void Start() { Emiservice = new EmiService(this); sersock = new SocketServer(CallbackThreadType.ctIOThread, Emiservice); System.Net.IPEndPoint endpoint; if (localIp == "*") { endpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, port); } else { endpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(localIp), port); } SocketListener sl = sersock.AddListener("EMI", endpoint); sl.Start(); IsRunning = true; }
static void Main(string[] args) { FastNetwork.Log.Trace.EnableConsole(); ServerHandler handler = new ServerHandler(); DefaultBinaryProtocol protocal = new DefaultBinaryProtocol(); SocketServer server = new SocketServer(handler, new DefaultEncoder(), new DefaultDecoder()); server.AddListener("tcp", new System.Net.IPEndPoint(IPAddress.Any, 8008)); try { server.Start(); } catch (Exception e) { Console.WriteLine(e.StackTrace); } Console.WriteLine("server start"); Console.ReadLine(); }
private void AddListener() { FEchoServer.AddListener(String.Empty, new IPEndPoint(IPAddress.Any, 8092), EncryptType.etNone, CompressionType.ctNone, new EchoCryptService.EchoCryptService(), 50, 3); }
static void Main(string[] args) { ThreadPool.SetMinThreads(4, 4); ThreadPool.SetMaxThreads(8, 8); //----- CspParameters used in CryptService. CspParameters param = new CspParameters(); param.KeyContainerName = "ALAZ_ECHO_SERVICE"; RSACryptoServiceProvider serverKey = new RSACryptoServiceProvider(param); //----- Socket Server! OnEventDelegate FEvent = new OnEventDelegate(Event); SocketServer echoServer = new SocketServer(new EchoSocketService.EchoSocketService(FEvent)); echoServer.Delimiter = new byte[] { 0xAA, 0xFF }; echoServer.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive; echoServer.SocketBufferSize = 4096; echoServer.MessageBufferSize = 4096 * 4; echoServer.IdleCheckInterval = 60000; echoServer.IdleTimeOutValue = 120000; //----- Socket Listener! SocketListener listener = echoServer.AddListener("Commom Port - 8090", new IPEndPoint(IPAddress.Any, 8090)); listener.AcceptThreads = 3; listener.BackLog = 50; listener.CompressionType = CompressionType.ctNone; listener.EncryptType = EncryptType.etNone; listener.CryptoService = new EchoCryptService.EchoCryptService(); echoServer.Start(); Console.WriteLine("Started!"); Console.WriteLine("----------------------"); string s; do { int iot = 0; int wt = 0; s = Console.ReadLine(); if (s.Equals("g")) { ThreadPool.GetAvailableThreads(out wt, out iot); Console.WriteLine("IOT " + iot.ToString()); Console.WriteLine("WT " + wt.ToString()); } } while (s.Equals("g")); try { echoServer.Stop(); echoServer.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } echoServer = null; Console.WriteLine("Stopped!"); Console.WriteLine("----------------------"); Console.ReadLine(); }
static void Main(string[] args) { //----- Set Threads! ThreadPool.SetMinThreads(4, 4); ThreadPool.SetMaxThreads(32, 32); SocketServer chatServer = new SocketServer(new ChatSocketService.ChatSocketService()); chatServer.Delimiter = new byte[] { 0xAA, 0xFF, 0xAA }; chatServer.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive; chatServer.SocketBufferSize = 1024; chatServer.MessageBufferSize = 512; //----- Socket Listener! SocketListener listener = chatServer.AddListener("Char Server", new IPEndPoint(IPAddress.Any, 8090)); listener.AcceptThreads = 3; listener.BackLog = 50; listener.CompressionType = CompressionType.ctNone; listener.EncryptType = EncryptType.etRijndael; listener.CryptoService = new ChatCryptService.ChatCryptService(); chatServer.Start(); Console.WriteLine(" Chat Server Started!"); Console.WriteLine("--------------------------------------"); string key; int iot = 0; int wt = 0; do { Console.WriteLine(" Press T <ENTER> for Threads"); Console.WriteLine(" Press C <ENTER> for Clients"); Console.WriteLine(" Press S <ENTER> for Stop Server"); Console.WriteLine("--------------------------------------"); Console.Write(" -> "); key = Console.ReadLine().ToUpper(); if (key.Equals("T")) { ThreadPool.GetAvailableThreads(out wt, out iot); Console.WriteLine("--------------------------------------"); Console.WriteLine(" I/O Threads " + iot.ToString()); Console.WriteLine(" Worker Threads " + wt.ToString()); Console.WriteLine("--------------------------------------"); } if (key.Equals("C")) { ISocketConnectionInfo[] infos = chatServer.GetConnections(); Console.WriteLine("\r\n--------------------------------------"); Console.WriteLine(" " + infos.Length.ToString() + " user(s)!\r\n"); foreach (ISocketConnectionInfo info in infos) { Console.WriteLine(" Connection Id " + info.ConnectionId.ToString()); Console.WriteLine(" User Name " + ((ConnectionData)info.CustomData).UserName); Console.WriteLine(" Ip Address " + info.RemoteEndPoint.Address.ToString()); Console.WriteLine("--------------------------------------"); } } } while (!key.Equals("S")); Console.WriteLine(" Chat Server Stopping!"); Console.WriteLine("--------------------------------------"); try { chatServer.Stop(); chatServer.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } chatServer = null; Console.WriteLine(" Chat Server Stopped!"); Console.WriteLine("--------------------------------------"); Console.ReadLine(); }