public void ConnectClientToServerClientDisconnects() { var server = new TcpipServer(_ipEndPoint); var e = new AutoResetEvent(false); var e1 = new AutoResetEvent(false); var e2 = new AutoResetEvent(false); bool servercompleted = false; bool servercompleted2 = false; bool clientcompleted = false; bool clientcompleted2 = false; bool onServerConnected = false; bool onClientConnected = false; IPEndPoint clientEndPoint = null; IPEndPoint clientEndPoint2 = null; server.NewClient = ch => { Assert.Equal(_ipEndPoint, (ch as ITcpIpChannel).LocalEndPoint); clientEndPoint = (ch as ITcpIpChannel).RemoteEndPoint; ch.OnConnect.Subscribe(u => onServerConnected = true, ex => Assert.True(false, ex.ToString()), () => servercompleted2 = true); ch.OnReceive.Subscribe(bb => Assert.True(false, "receive without send"), ex => Assert.True(false, ex.ToString()), () => { servercompleted = true; e2.Set(); }); e.Set(); }; server.StartListening(); try { var client = new TcpipClient(_ipEndPoint); client.OnConnect.Subscribe(u => { onClientConnected = true; clientEndPoint2 = client.LocalEndPoint; Assert.Equal(_ipEndPoint, client.RemoteEndPoint); e1.Set(); }, ex => Assert.True(false, ex.ToString()), () => clientcompleted2 = true); client.OnReceive.Subscribe(bb => Assert.True(false, "receive without send"), ex => Assert.True(false, ex.ToString()), () => clientcompleted = true); client.ConnectAsync(); Assert.True(e.WaitOne(TimeSpan.FromSeconds(10))); Assert.True(e1.WaitOne(TimeSpan.FromSeconds(10))); client.Dispose(); Assert.True(clientcompleted); Assert.True(clientcompleted2); Assert.True(e2.WaitOne(TimeSpan.FromSeconds(10))); Assert.True(servercompleted); Assert.True(servercompleted2); Assert.True(onClientConnected); Assert.True(onServerConnected); Assert.Equal(clientEndPoint, clientEndPoint2); } finally { server.StopListening(); } }
public void StartAndStopListeningWorks() { var server = new TcpipServer(_ipEndPoint); server.StartListening(); server.StopListening(); }