Beispiel #1
0
        private void AsyncConnect(IAsyncResult res)
        {
            AsyncSocketWrapper sender = null;
            try
            {
                sender = new AsyncSocketWrapper();
                sender.Create(this.Connection.EndAccept(res));
                if (sender.Socket == null)
                {
                    this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);

                    return;
                }
                if (this.OnClientConnect != null)
                {
                    this.OnClientConnect(sender);
                }
                sender.Socket.BeginReceive(sender.Buffer, 0, sender.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), sender);

                this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
            }
            catch (SocketException e)
            {
                Program.SaveException(e);
                Console.WriteLine(e);
                if (this.enabled)
                {
                    this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
                }
            }
            catch (ObjectDisposedException e)
            {
                Program.SaveException(e);
                Console.WriteLine(e);
            }
        }
Beispiel #2
0
 public void InvokeDisconnect(AsyncSocketWrapper Client)
 {
     if (Client != null)
     {
         try
         {
             if (Client.Socket.Connected)
             {
                 Client.Socket.Shutdown(SocketShutdown.Both);
                 Client.Socket.Close();
                 if (this.OnClientDisconnect != null)
                 {
                     this.OnClientDisconnect(Client);
                 }
                 Client.Connector = null;
                 Client = null;
             }
             else
             {
                 if (this.OnClientDisconnect != null)
                 {
                     this.OnClientDisconnect(Client);
                 }
                 Client.Connector = null;
                 Client = null;
             }
         }
         catch (ObjectDisposedException e)
         {
             Program.SaveException(e);
             Console.WriteLine(e);
         }
     }
 }