public void ShouldBeSilentAfterStopWhenStopped() { var listener = new TcpListener(9994); listener.Stop(); Assert.AreEqual(ListenerStatus.Stopped, listener.Status); }
public void ShouldBeListeningAfterStart() { var listener = new TcpListener(9992); listener.Start(); Assert.AreEqual(ListenerStatus.Listening, listener.Status); }
public void ShouldBeStoppedAfterStop() { var listener = new TcpListener(9993); listener.Start(); listener.Stop(); Assert.AreEqual(ListenerStatus.Stopped, listener.Status); }
public MainWindow() { InitializeComponent(); var r = new Random(); _port = r.Next(1500, 2000); _id = Guid.NewGuid(); _sessions = new Dictionary <IPEndPoint, Tuple <Peer, PascalStreamReader> >(); _listener = new TcpListener(_port); _comunicationManager = new CommunicationManager(_listener); _comunicationManager.ConnectionClosed += ChatOnMemberDisconnected; _comunicationManager.PeerConnected += ChatOnMemberConnected; _listener.Start(); _discovery = new UdpListener(3000); _discovery.UdpPacketReceived += DiscoveryOnUdpPacketReceived; _discovery.Start(); using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { socket.EnableBroadcast = true; var group = new IPEndPoint(IPAddress.Broadcast, 3000); var hi = Encoding.ASCII.GetBytes("Hi Peer2Net node here:" + _id + ":127.0.0.1:" + _port); socket.SendTo(hi, group); socket.Close(); } }
public MainWindow() { InitializeComponent(); var r = new Random(); _port = r.Next(1500, 2000); _id = Guid.NewGuid(); _sessions = new Dictionary<IPEndPoint, Tuple<Peer, PascalStreamReader>>(); _listener = new TcpListener(_port); _comunicationManager = new CommunicationManager(_listener); _comunicationManager.ConnectionClosed += ChatOnMemberDisconnected; _comunicationManager.PeerConnected += ChatOnMemberConnected; _listener.Start(); _discovery = new UdpListener(3000); _discovery.UdpPacketReceived += DiscoveryOnUdpPacketReceived; _discovery.Start(); using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { socket.EnableBroadcast = true; var group = new IPEndPoint(IPAddress.Broadcast, 3000); var hi = Encoding.ASCII.GetBytes("Hi Peer2Net node here:" + _id + ":127.0.0.1:" + _port); socket.SendTo(hi, group); socket.Close(); } }
public void ShouldAllowRestart() { var listener = new TcpListener(9995); listener.Start(); listener.Stop(); listener.Start(); Assert.AreEqual(ListenerStatus.Listening, listener.Status); }
public void Setup() { _listener = new TcpListener(9999); _connectedEvent = new ManualResetEvent(false); _communicationManager = new CommunicationManager(_listener); _communicationManager.PeerConnected += (sender, args) => { _peer = args.Peer; _connectedEvent.Set(); }; _listener.Start(); }
public void ShouldNotifyNewConnection() { var completion = new ManualResetEvent(false); var passed = false; var listener = new TcpListener(9996); listener.ConnectionRequested += (sender, args) => { passed = true; completion.Set(); }; listener.Start(); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, listener.Port)); completion.WaitOne(500); Assert.IsTrue(passed); }