Ejemplo n.º 1
0
 private void ClientStream(LobbyClient client)
 {
     while (true)
     {
         string response = GetResponse(client.socket);
         if (response != "")
         {
             string[] sections     = response.Split('|');
             string   responseType = sections[0];
             if (responseType == "PONG")
             {
                 Console.WriteLine("Got Pong from: {0}", client.socket.RemoteEndPoint);
                 client.pinging = false;
             }
             else if (responseType == "MESSAGE")
             {
                 BroadCastMessage(sections[1], client.socket);
                 Console.WriteLine(client.socket.RemoteEndPoint + ": " + sections[1]);
             }
         }
         else
         {
             clients.Remove(client);
             break;
         }
     }
 }
Ejemplo n.º 2
0
        override public void AddClient(Socket peer)
        {
            LobbyClient new_client = new LobbyClient(peer);

            new_client.stream = new Thread(() => ClientStream(new_client));
            new_client.stream.Start();
            clients.Add(new_client);
        }
Ejemplo n.º 3
0
 private void PingClient(LobbyClient client)
 {
     client.pinging = true;
     Console.WriteLine("Pinging Client: {0}", client.socket.RemoteEndPoint);
     try {
         client.socket.Send(Encoding.ASCII.GetBytes("PING|\r\n"));
         Thread.Sleep(10000);
         if (client.pinging)
         {
             client.socket.Close();
         }
     } catch (SocketException) {
         client.socket.Close();
     }
 }