public void Start( CancellationToken token ) { try { _server.Connect( _ipep ); } catch (SocketException e) { Console.WriteLine (e); } Thread.Sleep (1000); using (var ns = new NetworkStream (_server)) { var mp = new TcpMultiplexer (ns, "MPClient"); var rwStream = mp.CreateStream ("rwStream", TcpMultiplexer.Direction.InOut); var t2 = Task.Factory.StartNew(() => WriteToStream (rwStream, "rwStream", token, "Hello from Maria Alm")); var t3 = Task.Factory.StartNew(() => ReadFromStream( rwStream, "rwStream", token )); var writeableStream = mp.CreateStream ("channel1", TcpMultiplexer.Direction.Out); var t1 = Task.Factory.StartNew(() => WriteToStream (writeableStream, "channel1", token, "Hello from Teisendorf")); t1.Wait (token); t2.Wait (token); t3.Wait(token); } }
public void Start( CancellationToken token ) { _newsock.Bind(_ipep); _newsock.Listen(10); Console.WriteLine("Waiting for a client..."); var client = _newsock.Accept(); var newclient = (IPEndPoint)client.RemoteEndPoint; Console.WriteLine("Connected with {0} at port {1}", newclient.Address, newclient.Port); using (var ns = new NetworkStream (client)) { var mp = new TcpMultiplexer (); var capService = new CapService (mp); var rwStream = mp.CreateStream (CapName, TcpMultiplexer.Direction.InOut); var t1 = Task.Factory.StartNew (() => ReadAndAck (rwStream, CapName, token, capService)); t1.Wait (token); Console.WriteLine ("Disconnected from {0}", newclient.Address); ns.Close (); } }