static void Main(string[] args) { service = new TcpService("SimpleEchoServer.xml"); service.ConnectionEvent += new SessionConnectionEvent(ConnectionCallback); service.CloseEvent += new SessionCloseEvent(CloseCallback); service.ReceiveEvent += new SessionReceiveEvent(ReceiveCallback); service.MessageEvent += new SessionMessageEvent(MesssageCallback); service.Run(); Console.WriteLine("starting server!"); int update = Environment.TickCount; while (true) { System.Threading.Thread.Sleep(50); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); if (key.KeyChar == '1') { service.Stop(); } else if (key.KeyChar == '2') { service.Run(); } else if (key.KeyChar == '3') { } else if (key.KeyChar == '4') { service.StartConnect("127.0.0.1", Port, 1000, 0, null); } else if (key.KeyChar == 'q') { break; } } if (Environment.TickCount - update > 5000) { Console.WriteLine(service.ToString()); update = Environment.TickCount; } } service.Stop(); }
public static void SocketListen() { DataAccess access = new DataAccess(); TcpService service = new TcpService(); DataTable list = access.GetList("select * from serverinfo where id=1"); if ((list != null) && (list.Rows.Count != 0)) { int port = int.Parse(list.Rows[0]["port1"].ToString()); int num2 = int.Parse(list.Rows[0]["port2"].ToString()); service.Run(port); PaidComm.Run(num2); } else { service.Run(0x1f90); PaidComm.Run(0x1f91); } }
static void Main(string[] args) { TcpServiceConfig config = new TcpServiceConfig(); config.ReceviceBuffer = ReceiveBuffer; config.SendBuffer = ReceiveBuffer; config.SendCount = 10; config.MaxConnectionCount = MaxConnectionCount; config.UpdateSessionIntval = 50; config.SessionReceiveTimeout = 0;// 30 * 1000; config.MessageFactoryAssemblyName = "NetService"; config.MessageFactoryTypeName = "NetService.Message.SimpleBinaryMessageFactory"; service = new TcpService(config); service.ConnectionEvent += new SessionConnectionEvent(ConnectionCallback); service.CloseEvent += new SessionCloseEvent(CloseCallback); service.ReceiveEvent += new SessionReceiveEvent(ReceiveCallback); service.MessageEvent += new SessionMessageEvent(MesssageCallback); server = new ChatServer(service); service.Run(); service.StartListener(IPString, Port, Backlog); Console.WriteLine("starting server!"); int update = Environment.TickCount; while (true) { System.Threading.Thread.Sleep(50); ConsoleKeyInfo key = Console.ReadKey(true); if (key.KeyChar == 'q') { break; } if (Environment.TickCount - update > 5000) { Console.WriteLine(service.ToString()); update = Environment.TickCount; } } service.Stop(); }
static void Main(string[] args) { if (args.Length < 1) { return; } TcpServiceConfig config = new TcpServiceConfig(); config.ReceviceBuffer = ReceiveBuffer; config.SendBuffer = ReceiveBuffer; config.SendCount = 10; config.MaxConnectionCount = MaxConnectionCount; config.UpdateSessionIntval = 50; config.SessionReceiveTimeout = 30 * 1000; config.MessageFactoryAssemblyName = "NetService"; config.MessageFactoryTypeName = "NetService.Message.SimpleBinaryMessageFactory"; service = new TcpService(config); service.ConnectionEvent += new SessionConnectionEvent(ConnectionCallback); service.CloseEvent += new SessionCloseEvent(CloseCallback); service.ReceiveEvent += new SessionReceiveEvent(ReceiveCallback); service.MessageEvent += new SessionMessageEvent(MesssageCallback); client = new ChatClient(service); client.Account = args[0]; service.Run(); service.StartConnect(IPString, Port, 1000, 0, null); Console.WriteLine("starting client"); while (true) { string msg = Console.ReadLine(); if (msg == "quit") { break; } client.SendChat(msg); } service.Stop(); }
static void Main(string[] args) { rand = new ThreadLocal <Random>(() => { return(new Random(Environment.TickCount)); }); //TcpServiceConfig config = new TcpServiceConfig(); //config.ReceviceBuffer = ReceiveBuffer; //config.SendBuffer = ReceiveBuffer; //config.SendCount = 10; //config.MaxConnectionCount = MaxConnectionCount; //config.UpdateSessionIntval = 50; //config.SessionReceiveTimeout = 30 * 1000; //config.MessageFactoryAssemblyName = "NetService"; //config.MessageFactoryTypeName = "NetService.Message.SimpleBinaryMessageFactory"; service = new TcpService("SimpleClient.xml"); service.ConnectionEvent += new SessionConnectionEvent(ConnectionCallback); service.CloseEvent += new SessionCloseEvent(CloseCallback); service.ReceiveEvent += new SessionReceiveEvent(ReceiveCallback); service.Run(); Console.WriteLine("starting server!"); int update = Environment.TickCount; while (true) { System.Threading.Thread.Sleep(50); Parallel.ForEach(_sessions, (KeyValuePair <long, long> s) => { byte[] buf = new byte[1000]; for (int i = 0; i < buf.Length; ++i) { buf[i] = (byte)i; } service.SendToSession(s.Key, buf, 0, buf.Length, false); }); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); if (key.KeyChar == '1') { service.Stop(); } else if (key.KeyChar == '2') { service.Run(); } else if (key.KeyChar == '3') { } else if (key.KeyChar == '4') { service.StartConnect(IPString, Port, 1000, 1000, null); } else if (key.KeyChar == 'q') { break; } } if (Environment.TickCount - update > 5000) { Console.WriteLine(service.ToString()); update = Environment.TickCount; } } service.Stop(); }