Exemple #1
0
 public void Add(SyncSocketWrapper war)
 {
     lock (OnAdd)
         OnAdd.Enqueue(war);
 }
Exemple #2
0
        private void SyncConnect()
        {
            try
            {
                while (true)
                {
                    if (Connection.Disabled)
                        return;
                    if (!this.enabled)
                        return;
                    SyncSocketWrapper sender = null;
                    try
                    {
                        sender = new SyncSocketWrapper();
                        sender.Create(this.Connection.Accept());
                        if (this.OnClientConnect != null)
                        {
                            this.OnClientConnect(sender);
                        }
                        sender.BeginReceive(this);
                    }
                    catch (SocketException e)
                    {
                        Program.SaveException(e);
                        Console.WriteLine(e);

                    }
                    catch (ObjectDisposedException e)
                    {
                        Program.SaveException(e);
                        Console.WriteLine(e);
                    }
                    catch (Exception e) { Program.SaveException(e); }
                }
            }
            catch (ThreadAbortException e )
            {
                Program.SaveException(e);
                Console.WriteLine(e);
            }
        }
Exemple #3
0
 public void InvokeOnClientConnect(SyncSocketWrapper sender)
 {
     if (this.OnClientConnect != null)
     {
         this.OnClientConnect(sender);
     }
 }
Exemple #4
0
 public void InvokeOnClientReceive(SyncSocketWrapper sender, byte[] buffer)
 {
     if (this.OnClientReceive != null)
     {
         this.OnClientReceive(buffer, sender);
     }
 }
Exemple #5
0
        public void InvokeDisconnect(SyncSocketWrapper Client)
        {
            if (Client != null)
            {
                try
                {
                    if (Client.Socket.Connected)
                    {
                        Client.Socket.Disconnect(false);
                        Client.Socket.Shutdown(SocketShutdown.Both);
                        Client.Socket.Close();
                        if (this.OnClientDisconnect != null)
                            this.OnClientDisconnect(Client);
                        Client.Connector = null;
                        Client = null;
                    }
                    else
                    {
                        Client.Socket.Shutdown(SocketShutdown.Both);
                        Client.Socket.Close();
                        if (this.OnClientDisconnect != null)
                            this.OnClientDisconnect(Client);

                        Client.Connector = null;
                        Client = null;
                    }
                }
                catch (ObjectDisposedException e)
                {
                    Program.SaveException(e);
                    Console.WriteLine(e);
                }
            }
        }