コード例 #1
0
 /// <summary>
 /// Удаление выбранного клиента
 /// </summary>
 private void RemoveImp()
 {
     if (SelectedClient != null)
     {
         ClientsList.Remove(SelectedClient);
     }
 }
コード例 #2
0
        private void RecRemoveClientMsg(int msgSize, NetworkStream networkStream)
        {
            int msgIndex = 0;
            int startIndex, remainingSize;

            byte[] bytesFrom;
            string client;

            remainingSize = msgSize;
            bytesFrom     = new byte[msgSize];
            startIndex    = 0;
            try
            {
                while (msgIndex < msgSize)
                {
                    msgIndex += networkStream.Read(bytesFrom, startIndex, remainingSize);
                    if (msgIndex > 0 && msgIndex < msgSize)
                    {
                        remainingSize = msgSize - msgIndex;
                        startIndex    = msgIndex;
                        continue;
                    }
                    else if (0 == msgIndex)
                    {
                        networkStream.Close();
                        return;
                    }
                    networkStream.Flush();

                    client = Encoding.ASCII.GetString(bytesFrom);
                    log.Write("Server requested so Removing ClientID " + client + " from client List for server " + ServerIP);
                    lock (ClientsList)
                        ClientsList.Remove(client);
                }
            }
            catch (ObjectDisposedException)
            {
                throw;
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception ex)
            {
                log.Write("Exception in RemoveClient " + ex);
                Console.WriteLine("Exception in RemoveClient " + ex);
            }
        }
コード例 #3
0
ファイル: Utility.cs プロジェクト: Brett1981/PopcornViewer
        // One function thread for each TCP connection host keeps track of. Used to recieve and process messages from clients in the host.
        private void Speak(TcpClient ClientSocket, string Entity)
        {
            byte[] BytesFrom = new byte[65536];

            while (true)
            {
                try
                {
                    NetworkStream Stream = ClientSocket.GetStream();
                    Stream.Read(BytesFrom, 0, (int)ClientSocket.ReceiveBufferSize);
                    // Splits message on $
                    string[] Message = System.Text.Encoding.UTF8.GetString(BytesFrom).Split('$');
                    if (Message[0] == "")
                    {
                        ClientsList.Remove(Entity);
                        Broadcast("has left the room", Entity, false);
                        BroadcastClientsList();
                        return;
                    }
                    // Client communication handling
                    else
                    {
                        switch (Message[0])
                        {
                        case "PLAYLIST":
                            Message[1] = Decrypt(Message[1] + "$");
                            Message[2] = Decrypt(Message[2] + "$");
                            PlaylistUpdate(Message[1].Split(' '));
                            if (Message[2] != "")
                            {
                                Broadcast(Message[2], Entity, false);
                            }
                            Thread.Sleep(200);
                            BroadcastPlaylist();
                            break;

                        case "CURRENTLYPLAYING":
                            Message[1] = Decrypt(Message[1] + "$");
                            try { PlayVideo(Convert.ToInt32(Message[1]), false); }
                            catch { }
                            break;

                        case "PAUSE":
                            Broadcast("PAUSE", "", false);
                            Internal_Command = true;
                            YoutubeVideo_CallFlash("pauseVideo()");
                            Internal_Command = false;
                            break;

                        case "PLAY":
                            Broadcast("PLAY " + Message[1], "", false);
                            Internal_Command = true;
                            YoutubeVideo_CallFlash("playVideo()");
                            Internal_Command = false;
                            break;

                        case "REFRESH":
                            string sCurrentTime = YoutubeVideo_CallFlash("getCurrentTime()");
                            sCurrentTime = sCurrentTime.Remove(sCurrentTime.Length - 9).Remove(0, 8);
                            Broadcast("PLAY " + sCurrentTime, "", false);
                            Internal_Command = true;
                            YoutubeVideo_CallFlash("playVideo()");
                            Internal_Command = false;
                            break;

                        case "VOTETOSKIP":
                            Broadcast("VOTETOSKIP", "", false);
                            CallTimer();
                            break;

                        case "VOTE":
                            VoteCounter++;
                            break;

                        default:
                            Message[1] = Decrypt(Message[1] + "$");
                            Broadcast(Message[1], Entity, true);
                            break;
                        }
                    }
                }
                catch
                {
                    ClientsList.Remove(Entity);
                    Broadcast("has left the room", Entity, false);
                    BroadcastClientsList();
                    return;
                }
                Thread.Sleep(200);
            }
        }