Пример #1
0
 public Response Send(Request request)
 {
     Response response = null;
     TcpClient client = null;
     try
     {
         client = new TcpClient();
         client.Connect(Address, Port);
         BinaryFormatter serializer = new BinaryFormatter();
         serializer.Serialize(client.GetStream(), request);
         client.GetStream().Flush();
         BinaryFormatter deserializer = new BinaryFormatter();
         response = (Response)deserializer.Deserialize(client.GetStream());
     }
     catch (SocketException e)
     {
         response = new Response();
         response.type = ResponseType.Fail;
         response.param = "Ошибка соединения с сервером.\nВозможно Cервер не запущет или неправильные настройкаи клиента.\n\nСообщение:\n" + e.Message;
     }
     finally
     {
         if (client != null)
         {
             client.Close();
         }
     }
     return response;
 }
Пример #2
0
 private bool AnalizeResult(Response responce)
 {
     if (responce.type == ResponseType.Fail)
     {
         //do sometrhing else
         MessageBox.Show(responce.param.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return false;
     }
     return true;
 }