Ejemplo n.º 1
0
 public void Process()
 {
     try
     {
         if (ClientSocket.Available == 0)
         {
             return;
         }
         object obj = NetworkCommon.RecievePacket(ClientSocket);
         if (obj != null)
         {
             if (_ProcessPayload != null)
             {
                 // process deserialized object
                 object oo = _ProcessPayload(obj);
                 // create packet with return of process
                 NetworkCommon.SendPacket(false, ClientSocket, oo);
                 return;
             }
         }
     }
     catch (IOException)
     {
         // All the data has arrived; put it in response.
         Close();
     }
     catch (SocketException)
     {
         // conection broken
         Close();
     }
 }
Ejemplo n.º 2
0
        public object Send(object data)
        {
            try
            {
                if (_tcpclient.Connected == false)
                {
                    Connect();
                }
                if (_tcpclient.Connected)
                {
                    return(NetworkCommon.SendPacket(true, _tcpclient, data));
                }
                return(null);
            }
            catch (Exception ex)
            {
                log.Debug("NetworkClient", "send ex =" + ex);

                NetworkStream ns = _tcpclient.GetStream();
                if (ns != null)
                {
                    ns.Close();
                }
                if (_tcpclient != null)
                {
                    _tcpclient.Close();
                }

                return(null);
            }
        }