public void PortConstructorTest()
 {
     var socket = new PeerSocket(104);
     Assert.IsNotNull(socket, "Portparameter constructor failed to create an object");
     Assert.False(socket.Bound, "Socket is connected to a restricted port without elevated rights");
     Assert.False(socket.Open(), "Socket is listening on a restricted port");
     socket.Dispose();
     Assert.False(socket.Bound, "The socket is bound longer than expected");
 }
 public void EndPointConstructorTest()
 {
     var socket = new PeerSocket(new IPEndPoint(IPAddress.IPv6None, 12345));
     Assert.IsNotNull(socket, "EndPoint constructor failed to create an object");
     Assert.True(socket.Bound, "Constructor was not able to bind to socket");
     Assert.True(socket.Open(), "Socket can't open the specified port");
     socket.Dispose();
     Assert.False(socket.Bound, "The socket is bound longer than expected");
 }
 public void ParameterlessPeerConstructorTest()
 {
     var socket = new PeerSocket();
     Assert.IsNotNull(socket, "Parameterless constructor failed to create an object");
     Assert.True(socket.Bound, "Parameterless constructor was not able to bind to socket");
     Assert.True(socket.Open(), "Socket can't open default port");
     Assert.AreEqual(new IPEndPoint(IPAddress.IPv6Any, 42337), socket.LocalEndPoint);
     socket.Dispose();
     Assert.False(socket.Bound, "The socket is bound longer than expected");
 }
示例#4
0
        /// <summary>
        /// Constructor to specify the local endpoint that the underlying socket is listening to.
        /// </summary>
        /// <param name="localEndPoint">The local endpoint to listen to</param>
        /// <exception cref="System.Exception">is thrown when the underlying socket could not bind 
        /// to the specified EndPoint</exception>
        public MessageRouter(IPEndPoint localEndPoint)
        {
            _socket = new PeerSocket(localEndPoint);
            if (!_socket.IsBound)
                throw new Exception("The underlying peer socket can't be initialized");
            _socket.MessageReceived += OnSocketMessageReceived;
            _socket.MessageSent += OnSocketMessageSent;
            _socket.ReceiveMessages();

            _connectedApplications = new List<IApplication>();
        }