Ejemplo n.º 1
0
 public void SendMessage(SyncServerMessage message)
 {
     if (!Running)
         return;
     try
     {
         Formatter.Serialize(_client.GetStream(), message);
     }
     catch (SerializationException e)
     {
         Log("Sending to server failed, SerializationException: ", e.Message);
     }
     catch (IOException e)
     {
         Log("Sending to server failed, IOException: ", e.Message);
     }
 }
Ejemplo n.º 2
0
 public void SendMessage(SyncServerMessage message)
 {
     if (!Running)
     {
         return;
     }
     try
     {
         Formatter.Serialize(_client.GetStream(), message);
     }
     catch (SerializationException e)
     {
         Log("Sending to server failed, SerializationException: ", e.Message);
     }
     catch (IOException e)
     {
         Log("Sending to server failed, IOException: ", e.Message);
     }
 }
Ejemplo n.º 3
0
        private void HandleClient(object arg)
        {
            TcpClient client = (TcpClient)arg;

            _client = client;
            _clients.Add(client);
            var stream = client.GetStream();

            var clientName = client.Client.RemoteEndPoint.ToString();

            Log("Client {0} connected.", clientName);

            using (client)
                while (Running && _clients.Contains(client))
                {
                    try
                    {
                        SyncServerMessage message = (SyncServerMessage)Formatter.Deserialize(stream);
                        message.Execute(Context, client, this);
                    }
                    catch (EndOfStreamException e)
                    {
                        Log("Client connection {0} failed, EndOfStreamException: {1}", clientName, e.Message);
                        break;
                    }
                    catch (SerializationException e)
                    {
                        Log("Client connection {0} failed, SerializationException: {1}", clientName, e.Message);
                        break;
                    }
                    catch (IOException e)
                    {
                        Log("Client connection {0} failed, IOException: {1}", clientName, e.Message);
                        break;
                    }
                }
            _clients.Remove(client);
        }