Beispiel #1
0
 private void GetRequest()
 {
     while (true)
     {
         byte[] request = RequestsReceiver.ReceiveTo(Defines.RequestSize);
         string ip      = request[0].ToString() + "." + request[1].ToString() + "." + request[2].ToString() + "." + request[3].ToString();
         if (ip == GetHostIP())
         {
             continue;
         }
         FlagsRequest numberRequest = (FlagsRequest)request[4];
         byte[]       nameInBytes   = new byte[Defines.maxLenghtName];
         for (int i = Defines.startPositionNameInRequest, j = 0; (i < Defines.RequestSize) && (j < nameInBytes.Length); i++, j++)
         {
             nameInBytes[j] = request[i];
         }
         string name = TranslateBytesInName(nameInBytes);
         if (numberRequest == FlagsRequest.FSetInfo)
         {
             AddUserIpAndChatNumber(ip, name);
         }
         if (numberRequest == FlagsRequest.FGetInfo)
         {
             SendRequest((byte)FlagsRequest.FSetInfo, ip);
             AddUserIpAndChatNumber(ip, name);
         }
         if (numberRequest == FlagsRequest.FTrySetUser)
         {
             if (!sendVideo.ContainUser(ip))
             {
                 receiveVideo.AddUser(ip, name);
                 receiveVideo.AddAnswerUser(ip);
             }
         }
         if (numberRequest == FlagsRequest.FAddUser)
         {
             AddNewUserInGroup(ip, name);
         }
         if (numberRequest == FlagsRequest.FRemoveUser)
         {
             RemoveUserWithGroup(ip);
         }
         if (numberRequest == FlagsRequest.FNoAddUser)
         {
             receiveVideo.RemoveCallUser(ip);
             RemoveUserWithGroup(ip);
         }
     }
 }
Beispiel #2
0
        public void SendRequest(FlagsRequest numberRequest, string ip)
        {
            string ipAddress = GetHostIP();

            byte[] request = new byte[Defines.RequestSize];
            request[0] = (byte)GetNumberOfIp(ipAddress, 1);
            request[1] = (byte)GetNumberOfIp(ipAddress, 2);
            request[2] = (byte)GetNumberOfIp(ipAddress, 3);
            request[3] = (byte)GetNumberOfIp(ipAddress, 4);
            request[4] = (byte)numberRequest;
            byte[] nameInBytes = TranslateNameInBytes(myUserName, Defines.maxLenghtName);
            for (int i = Defines.startPositionNameInRequest, j = 0; (i < Defines.RequestSize) && (j < nameInBytes.Length); i++, j++)
            {
                request[i] = nameInBytes[j];
            }
            RequestSender.Connect(ip, Defines.portGetRequests);
            if (RequestSender.Connected)
            {
                RequestSender.SendTo(request);
            }
        }