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(); } } }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); SocketAsyncEventArgsPool.ConfigBeforeCreateInstance(5000,4096,4096); SocketAsyncEventArgsPool.GetInstance();// <--warm up; using (var listener = new ReactiveTCPLibrary.ReactiveTCPListener(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 54321))) { TcpClientEventContainer.DefaultInstance.ClientException += new EventHandler<ClientExceptionEventArg>(DefaultInstance_ClientException); using (var sub = listener.Subscribe ( socket => { try { var cp = new ConnectionPair(socket, "127.0.0.1", 80); cp.Pin(); ////var client = new ReactiveTCPLibrary.ReactiveTcpClient<object, string>(socket, //// new NaturalCutter<string>(stser), //// new NaturalPacker<string>(stser), //// () => SocketAsyncEventArgsPool.GetInstance().GetResourceTokenFromPool(), //// new NewArrayByteSegmentLocator()); //bag.AddOrUpdate(client, client, (a, b) => client); //var x = client.Subscribe(p => //{ // client.OnNext(new Tuple<string, PacketSentCallback<string>>(p, (PacketSentCallback<string>)null)); //}); } catch (Exception) { return; } // GCHandle.Alloc(client, GCHandleType.Pinned); // GCHandle.Alloc(x, GCHandleType.Pinned); } ) ) { Console.Read(); } } }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); SocketAsyncEventArgsPool.ConfigBeforeCreateInstance(5000, 4096, 4096); SocketAsyncEventArgsPool.GetInstance();// <--warm up; using (var listener = new ReactiveTCPLibrary.ReactiveTCPListener(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 54321))) { TcpClientEventContainer.DefaultInstance.ClientException += new EventHandler <ClientExceptionEventArg>(DefaultInstance_ClientException); using (var sub = listener.Subscribe ( socket => { try { var cp = new ConnectionPair(socket, "127.0.0.1", 80); cp.Pin(); ////var client = new ReactiveTCPLibrary.ReactiveTcpClient<object, string>(socket, //// new NaturalCutter<string>(stser), //// new NaturalPacker<string>(stser), //// () => SocketAsyncEventArgsPool.GetInstance().GetResourceTokenFromPool(), //// new NewArrayByteSegmentLocator()); //bag.AddOrUpdate(client, client, (a, b) => client); //var x = client.Subscribe(p => //{ // client.OnNext(new Tuple<string, PacketSentCallback<string>>(p, (PacketSentCallback<string>)null)); //}); } catch (Exception) { return; } // GCHandle.Alloc(client, GCHandleType.Pinned); // GCHandle.Alloc(x, GCHandleType.Pinned); } ) ) { Console.Read(); } } }