Exemplo n.º 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);
         }
     }
 }
        private void btn_Call_Click(object sender, EventArgs e)
        {
            string callUserIp = "";

            lock (cb_Users)
            {
                if ((cb_Users.Items != null) && (cb_Users.Items.Count != 0) && (cb_Users.SelectedIndex != -1))
                {
                    callUserIp = getRequests.listUsersIp[cb_Users.SelectedIndex];
                }
            }
            if ((callUserIp != "") && (!sendVideo.ContainUser(callUserIp)))
            {
                getRequests.Call(callUserIp);
            }
        }