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(); } } }
public ConnectionPair(Socket incomingSocket, string outGoingHost, int outGoingPort) { var outGoingSocket = new TcpClient(outGoingHost, outGoingPort).Client; IncomingClient = new ReactiveTCPLibrary.ReactiveTcpClient<ConnectionPair, ArraySegment<byte>> ( incomingSocket, new NodoCutter(), new NaturalPacker<ArraySegment<byte>>(new NodoSerializer()), () => SocketAsyncEventArgsPool.GetInstance().GetResourceTokenFromPool(), null ) { ConnectionContext = this } ; OutgoingClient = new ReactiveTCPLibrary.ReactiveTcpClient<ConnectionPair, ArraySegment<byte>> ( outGoingSocket, new NodoCutter(), new NaturalPacker<ArraySegment<byte>>(new NodoSerializer()), () => SocketAsyncEventArgsPool.GetInstance().GetResourceTokenFromPool(), null ) { ConnectionContext = this } ; var dis1 = IncomingClient .Subscribe( x => { OutgoingClient.OnNext(new Tuple<ArraySegment<byte>, ReactiveTCPLibrary.PacketSentCallback<ArraySegment<byte>>, AbortionChecker>(x, null,null)); }, e => { OutgoingClient.OnError(e); ConnectionAborted(this, _empty); }, () => { OutgoingClient.OnCompleted(); ConnectionAborted(this, _empty); } ); var dis2 = OutgoingClient .Subscribe( x => { IncomingClient.OnNext(new Tuple<ArraySegment<byte>, ReactiveTCPLibrary.PacketSentCallback<ArraySegment<byte>>,AbortionChecker>(x, null,null)); }, e => { IncomingClient.OnError(e); ConnectionAborted(this, _empty); }, () => { IncomingClient.OnCompleted(); ConnectionAborted(this, _empty); } ); _disposeList = new List<IDisposable> { OutgoingClient, IncomingClient, dis1, dis2 }; IncomingClient.Start(); OutgoingClient.Start(); }
public ConnectionPair(Socket incomingSocket, string outGoingHost, int outGoingPort) { var outGoingSocket = new TcpClient(outGoingHost, outGoingPort).Client; IncomingClient = new ReactiveTCPLibrary.ReactiveTcpClient <ConnectionPair, ArraySegment <byte> > ( incomingSocket, new NodoCutter(), new NaturalPacker <ArraySegment <byte> >(new NodoSerializer()), () => SocketAsyncEventArgsPool.GetInstance().GetResourceTokenFromPool(), null ) { ConnectionContext = this } ; OutgoingClient = new ReactiveTCPLibrary.ReactiveTcpClient <ConnectionPair, ArraySegment <byte> > ( outGoingSocket, new NodoCutter(), new NaturalPacker <ArraySegment <byte> >(new NodoSerializer()), () => SocketAsyncEventArgsPool.GetInstance().GetResourceTokenFromPool(), null ) { ConnectionContext = this } ; var dis1 = IncomingClient .Subscribe( x => { OutgoingClient.OnNext(new Tuple <ArraySegment <byte>, ReactiveTCPLibrary.PacketSentCallback <ArraySegment <byte> >, AbortionChecker>(x, null, null)); }, e => { OutgoingClient.OnError(e); ConnectionAborted(this, _empty); }, () => { OutgoingClient.OnCompleted(); ConnectionAborted(this, _empty); } ); var dis2 = OutgoingClient .Subscribe( x => { IncomingClient.OnNext(new Tuple <ArraySegment <byte>, ReactiveTCPLibrary.PacketSentCallback <ArraySegment <byte> >, AbortionChecker>(x, null, null)); }, e => { IncomingClient.OnError(e); ConnectionAborted(this, _empty); }, () => { IncomingClient.OnCompleted(); ConnectionAborted(this, _empty); } ); _disposeList = new List <IDisposable> { OutgoingClient, IncomingClient, dis1, dis2 }; IncomingClient.Start(); OutgoingClient.Start(); }