static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("params: [Port]"); Console.WriteLine("Press any key..."); Console.ReadLine(); return; } var port = int.Parse(args[0]); SocketAsyncEventArgsPool.ConfigBeforeCreateInstance(300000); var pool = SocketAsyncEventArgsPool.GetInstance(); using (var listener = new ReactiveTCPLibrary.ReactiveTCPListener(new System.Net.IPEndPoint(System.Net.IPAddress.Any, port))) { TcpClientEventContainer.DefaultInstance.ClientException += new EventHandler<ClientExceptionEventArg>(DefaultInstance_ClientException); var stser = new SimpleStringSerializer(); using (var sub = listener.Subscribe ( socket => { try { var client = new ReactiveTCPLibrary.ReactiveTcpClient<object, string>(socket, new NaturalCutter<string>(stser), new NaturalPacker<string>(stser), () => pool.GetResourceTokenFromPool(), new NewArrayByteSegmentLocator()); bag.AddOrUpdate(client, client, (a,b)=>client); var x = client.Subscribe(p => { client.OnNext (new Tuple<string,PacketSentCallback<string>,AbortionChecker>(p,(PacketSentCallback<string>) null,null)); }); client.Start(); } catch (Exception) { return; } // GCHandle.Alloc(client, GCHandleType.Pinned); // GCHandle.Alloc(x, GCHandleType.Pinned); } ) ) { Console.WriteLine("Ready"); Console.Read(); } } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("params: [Port]"); Console.WriteLine("Press any key..."); Console.ReadLine(); return; } var port = int.Parse(args[0]); SocketAsyncEventArgsPool.ConfigBeforeCreateInstance(300000); var pool = SocketAsyncEventArgsPool.GetInstance(); using (var listener = new ReactiveTCPLibrary.ReactiveTCPListener(new System.Net.IPEndPoint(System.Net.IPAddress.Any, port))) { TcpClientEventContainer.DefaultInstance.ClientException += new EventHandler <ClientExceptionEventArg>(DefaultInstance_ClientException); var stser = new SimpleStringSerializer(); using (var sub = listener.Subscribe ( socket => { try { var client = new ReactiveTCPLibrary.ReactiveTcpClient <object, string>( socket, new NaturalCutter <string>(stser), new NaturalPacker <string>(stser), () => pool.GetResourceTokenFromPool(), new NewArrayByteSegmentLocator()); bag.AddOrUpdate(client, client, (a, b) => client); var x = client.Subscribe(p => { client.OnNext(new Tuple <string, PacketSentCallback <string>, AbortionChecker>(p, (PacketSentCallback <string>)null, null)); }); client.Start(); } catch (Exception) { return; } } ) ) { Console.WriteLine("Ready"); Console.Read(); } } }