private void SyncConnect()
        {
            try
            {
                while (true)
                {
                    if (Connection.Disabled)
                        return;
                    if (!this.enabled)
                        return;
                    SyncSocketWrapper sender = null;
                    try
                    {
                        //String IPAdress = "";
                        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);
            }
        }
 public void InvokeOnClientConnect(SyncSocketWrapper sender)
 {
     if (this.OnClientConnect != null)
     {
         this.OnClientConnect(sender);
     }
 }
 public void InvokeOnClientReceive(SyncSocketWrapper sender, byte[] buffer)
 {
     if (this.OnClientReceive != null)
     {
         this.OnClientReceive(buffer, sender);
     }
 }
        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);
                }
            }
        }