Esempio n. 1
0
 private void callback(IAsyncResult ar)
 {
     try
     {
         Sck.EndReceive(ar);
         byte[] buf = new byte[8192];
         int    rec = Sck.Receive(buf, buf.Length, 0);
         if (rec > 0)
         {
             if (rec < buf.Length)
             {
                 Array.Resize <byte>(ref buf, rec);
             }
             if (Received != null)
             {
                 Received(this, buf);
             }
             Sck.BeginReceive(new byte[] { 0 }, 0, 0, 0, callback, null);
         }
         else
         {
             close();
         }
     }
     catch (Exception ex)
     {
         // MessageBox.Show(ex.ToString());
         close();
         //if(Disconnected!=null)
         //{
         //    Disconnected(this);
         //}
     }
 }
Esempio n. 2
0
 public void close()
 {
     //Sck.Shutdown(SocketShutdown.Both);
     Sck.Close(); Sck.Dispose();
 }