Example #1
0
        public void CreateServerAddressWithLocalhostHostname()
        {
            Uri uri = new Uri("tcp://localhost:1024/");
            ServerAddress address = new ServerAddress(uri);

            Assert.Equal(uri, address.Url);
            Assert.Equal(1024, address.Port);
            Assert.Equal("127.0.0.1", address.IPAddress.ToString());
        }
Example #2
0
        public void CreateServerAddressWithoutPort()
        {
            Uri uri = new Uri("tcp://localhost/");
            ServerAddress address = new ServerAddress(uri);

            Assert.Equal(uri, address.Url);
            Assert.Equal(uri.Port, address.Port);
            Assert.Equal("127.0.0.1", address.IPAddress.ToString());
        }
Example #3
0
        public void CreateServerAddressWithIpAdress()
        {
            Uri uri = new Uri("tcp://10.20.30.40:1024/");
            ServerAddress address = new ServerAddress(uri);

            Assert.Equal(uri, address.Url);
            Assert.Equal(1024, address.Port);
            Assert.Equal("10.20.30.40", address.IPAddress.ToString());
        }
Example #4
0
        static ObjectServer()
        {
            DataLock = new object();

            // TODO: Now it is not possible to start the server at a
            // configured address like 127.0.0.1. For testing purposes it
            // could be configurable.
            server = new TcpServer();
            ServerAddress = server.Address;
            server.RequestReceived += OnRequestReceived;
        }
Example #5
0
 public TcpClient(ServerAddress serverAddress)
 {
     ServerAddress = serverAddress;
 }
Example #6
0
 internal RemoteObjectAddress(ServerAddress serverAddress, int objectID)
 {
     ServerAddress = serverAddress;
     ObjectID = objectID;
 }
Example #7
0
        public void SerializeAndDeserializeAddress(string uri)
        {
            ServerAddress address = new ServerAddress(new Uri(uri));
            string serializedAddress = address.Serialize();
            ServerAddress deserializedAddress = ServerAddress.Deserialize(serializedAddress);

            Assert.Equal(address, deserializedAddress);
        }
Example #8
0
 public void CheckIsLocalProperty(string uri, bool expectedIsLocal)
 {
     ServerAddress address = new ServerAddress(new Uri(uri));
     Assert.Equal(expectedIsLocal, address.IsLocal);
 }
Example #9
0
        /// <summary>
        /// Deserialize address object from string.
        /// </summary>
        /// <param name="serialized">Serialized address. Must not be null.</param>
        /// <returns>Deserialized object</returns>
        public static ServerAddress Deserialize(string serialized)
        {
            if (serialized == null)
            {
                throw new ArgumentNullException("serialized");
            }
            Uri url = new Uri(serialized);
            int port = url.Port;
            string host = url.Host;
            // TODO: the chosen IP address might not match with the one
            // provided in the URI
            IPAddress ipAddress = ChooseIPAddress(host);

            var result = new ServerAddress(url, ipAddress, port);
            return result;
        }
Example #10
0
        /// <summary>
        /// Generates a server address for local computer.
        /// </summary>
        /// <returns>Local server address</returns>
        public static ServerAddress GetLocalServerAddress()
        {
            int port = rnd.Next(PortRangeStart, PortRangeEnd);

            string localHostName = Dns.GetHostName();
            IPAddress ipAddress = ChooseIPAddress(localHostName);

            Uri url = new Uri(string.Format("tcp://{0}:{1}", ipAddress, port));
            ServerAddress result = new ServerAddress(url, ipAddress, port);
            return result;
        }