private static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); //----- Socket Server! OnEventDelegate FEvent = new OnEventDelegate(Event); SocketServer echoServerProvider = new SocketServer(CallbackThreadType.ctWorkerThread, new EchoSocketService.EchoSocketService(FEvent)); echoServerProvider.Context.DelimiterEncrypt = new byte[] { 0xFF, 0x00, 0xFE, 0x01, 0xFD, 0x02 }; echoServerProvider.Context.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive; echoServerProvider.Context.SocketBufferSize = 1024; echoServerProvider.Context.MessageBufferSize = 2048; echoServerProvider.Context.IdleCheckInterval = 60000; echoServerProvider.Context.IdleTimeOutValue = 120000; //----- Socket Listener! SocketListener listener = echoServerProvider.AddListener("Commom Port - 8090", new IPEndPoint(IPAddress.Any, 8090)); listener.AcceptThreads = 3; listener.BackLog = 100; listener.Context.Host = echoServerProvider; listener.Context.EncryptType = EncryptType.etNone; listener.Context.CompressionType = CompressionType.ctNone; listener.Context.CryptoService = new EchoCryptService.EchoCryptService(); echoServerProvider.Start(); Console.WriteLine("Started!"); Console.WriteLine("----------------------"); int iot = 0; int wt = 0; ThreadPool.GetAvailableThreads(out wt, out iot); Console.WriteLine("Threads Work - " + wt.ToString()); Console.WriteLine("Threads I/O - " + iot.ToString()); string s; do { s = Console.ReadLine(); if (s.Equals("g")) { ThreadPool.GetAvailableThreads(out wt, out iot); Console.WriteLine("Threads Work " + iot.ToString()); Console.WriteLine("Threads I/O " + wt.ToString()); } } while (s.Equals("g")); try { echoServerProvider.Stop(); echoServerProvider.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } echoServerProvider = null; Console.WriteLine("Stopped!"); Console.WriteLine("----------------------"); Console.ReadLine(); }
private static void Main(string[] args) { SocketServer chatServer = new SocketServer(CallbackThreadType.ctWorkerThread, new ChatSocketService.ChatSocketService()); chatServer.Context.DelimiterEncrypt = new byte[] { 0xAA, 0xFF, 0xAA }; chatServer.Context.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive; chatServer.Context.SocketBufferSize = 1024; chatServer.Context.MessageBufferSize = 512; //----- Socket Listener! SocketListener listener = chatServer.AddListener("Char Server", new IPEndPoint(IPAddress.Any, 8090)); listener.AcceptThreads = 3; listener.BackLog = 50; listener.Context.CompressionType = CompressionType.ctNone; listener.Context.EncryptType = EncryptType.etRijndael; listener.Context.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")) { ISocketConnection[] infos = chatServer.GetConnections(); Console.WriteLine("\r\n--------------------------------------"); Console.WriteLine(" " + infos.Length.ToString() + " user(s)!\r\n"); foreach (ISocketConnection info in infos) { Console.WriteLine(" Connection Id " + info.Context.ConnectionId.ToString()); Console.WriteLine(" User Name " + ((ConnectionData)info.Context.UserData).UserName); Console.WriteLine(" Ip Address " + info.Context.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(); }