Ejemplo n.º 1
0
        public void TestEquals()
        {
            ExtendedUser exUserToTest = new ExtendedUser(new User("Tom", -1), IPAddress.Parse("192.168.23.1"), 1234);
            ExtendedUser exUserEqual = new ExtendedUser(new User("Tom", -1), IPAddress.Parse("192.168.23.1"), 1234);
            ExtendedUser exUserUnequalName = new ExtendedUser(new User("Tomi", -1), IPAddress.Parse("192.168.23.1"), 1234);
            ExtendedUser exUserUnequalId = new ExtendedUser(new User("Tom", 3), IPAddress.Parse("192.168.23.1"), 1234);
            ExtendedUser exUserUnequalIp = new ExtendedUser(new User("Tom", -1), IPAddress.Parse("192.168.26.1"), 1234);
            ExtendedUser exUserUnequalPort = new ExtendedUser(new User("Tom", -1), IPAddress.Parse("192.168.23.1"), 5234);

            Assert.True(exUserToTest.Equals(exUserEqual));
            Assert.False(exUserToTest.Equals(exUserUnequalName));
            Assert.False(exUserToTest.Equals(exUserUnequalId));
            Assert.True(exUserToTest.Equals(exUserUnequalIp));
            Assert.True(exUserToTest.Equals(exUserUnequalPort));
        }
Ejemplo n.º 2
0
        public void TestParseFromMessage()
        {
            string correctResult = "TCPConnectTo;TestUser;-1;;;127.0.0.1;12345";

            ExtendedUser exUserToTest = new ExtendedUser(new User("Tom",-1),IPAddress.Parse("192.168.23.1"),1234);
            Message message = new Message("192.168.23.1;1234");
            message.FromUser = new User("Tom", -1);
            message.ToUser = null;
            Assert.AreEqual(exUserToTest.Name, ExtendedUser.ParseFromMessage(message).Name);
            Assert.AreEqual(exUserToTest.Id, ExtendedUser.ParseFromMessage(message).Id);
            Assert.AreEqual(exUserToTest.IpAddress, ExtendedUser.ParseFromMessage(message).IpAddress);
            Assert.AreEqual(exUserToTest.Port, ExtendedUser.ParseFromMessage(message).Port);
            Assert.True(exUserToTest.Equals(exUserToTest));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Connect to the given address external user, who has the address informations inside.
 /// </summary>
 /// <param name="exUser"></param>
 internal bool ManualConnectToExUser(ExtendedUser exUser)
 {
     bool success = false;
     lock (incomingConnectionLock)
     {
         if (control.GraphicControl.CurrentlyActiveChatUser != null && exUser.Equals(control.GraphicControl.CurrentlyActiveChatUser)) { return false; }
         if (!ConnectionOverServer)
         {
             try {
                 success = tcpClient.ReConnect(exUser.IpAddress, exUser.Port);
                 if (success)
                 {
                     ConnectionOverClient = true;
                 }
             }catch(SocketException ex)
             {
                 CloseConnectionFromClient();
             }
         }
     }
     return success;
 }