Пример #1
0
        public void SendWhois(BroadcastChatClient client)
        {
            StringBuilder sb = new StringBuilder("WHOIS ");

            sb.AppendFormat("{0} ", client.Nick);
            sb.AppendFormat("Connected: {0} ", TimeConnected.ToString().Replace(" ", string.Empty));
            sb.AppendFormat("IDLE: {0} ", client.Watch.ElapsedMilliseconds - client.TimeOfLastMessage.Milliseconds);
            sb.AppendFormat("IP: {0} ", ((IPEndPoint)client.TcpClient.Client.RemoteEndPoint).Address.ToString());
            sb.AppendFormat("PING: {0}", client.Ping);
            Send(sb.ToString());
        }
Пример #2
0
 private void pingThread(BroadcastChatClient client)
 {
     try
     {
         while (true)
         {
             client.Send("PING");
             Thread.Sleep(PING_TIMEOUT);
         }
     }
     catch (IOException)
     {
         OnClientDisconnected(new ClientDisconnectedEventArgs(client));
     }
 }
Пример #3
0
 private void listenForConnectionsThread()
 {
     while (true)
     {
         BroadcastChatClient client;
         try
         {
             client = new BroadcastChatClient(listener.AcceptTcpClient());
             client.ListenThread = new Thread(() => listenForMessagesThread(client));
             client.PingThread   = new Thread(() => pingThread(client));
             client.ListenThread.Start();
             client.PingThread.Start();
             OnClientConnected(new ClientConnectedEventArgs(client));
         }
         catch (IOException)
         {
         }
     }
 }
Пример #4
0
 private void listenForMessagesThread(BroadcastChatClient client)
 {
     try
     {
         while (true)
         {
             string message = client.Read();
             if (message == PONG_MESSAGE)
             {
                 client.Ping = 0;
             }
             else
             {
                 OnClientMessageReceived(new ClientMessageReceivedEventArgs(client, message));
             }
         }
     }
     catch (IOException)
     {
         OnClientDisconnected(new ClientDisconnectedEventArgs(client));
     }
 }