Example #1
0
 private void DataReceived(IAsyncResult res)
 {
     try
     {
         SocketError err = SocketError.Success;
         int received = 0;
         if (((Socket)res.AsyncState).Connected) received = ((Socket)res.AsyncState).EndReceive(res, out err);
         if (received <= 0 || err != SocketError.Success)
         {
             this.Disconnect();
             return;
         }
         DataEventArgs data = new DataEventArgs(this, buffer, received);
         this.onDataReceived(this, data);
     }
     catch
     {
         this.Disconnect();
     }
 }
Example #2
0
 void RemoteClient_onDataReceived(object sender, DataEventArgs e)
 {
     Client.Client.SendAsync(e.Buffer, e.Offset, e.Count);
     RemoteClient.ReceiveAsync();
 }
Example #3
0
 public void SendAsync(byte[] buff, int offset, int count)
 {
     try
     {
         if (this.Sock != null && this.Sock.Connected)
         {
             DataEventArgs data = new DataEventArgs(this, buff, count);
             this.onDataSent(this, data);
             this.Sock.BeginSend(buff, offset, count, SocketFlags.None, new AsyncCallback(DataSent), this.Sock);
         }
     }
     catch
     {
         this.Disconnect();
     }
 }