Exemplo n.º 1
0
 private void OnReceive(TcpSocketEventArgs value, int len, byte[] buff, ushort tag)
 {
     if (Receive != null)
     {
         Receive(this, value, len, buff, tag);
     }
 }
Exemplo n.º 2
0
 private void OnError(Exception ex, TcpSocketEventArgs e)
 {
     if (Error != null)
     {
         Error(ex, e);
     }
 }
Exemplo n.º 3
0
 private void OnConnected(TcpSocketEventArgs value)
 {
     if (Connected != null)
     {
         Connected(this, value);
     }
 }
Exemplo n.º 4
0
        private void ConnectCallBack(IAsyncResult ar)
        {
            object[] parobj       = (object[])ar.AsyncState;
            Socket   ClientSocket = (Socket)parobj[0];
            short    sign         = (short)parobj[1];

            if (parobj.Length > 2)
            {
                string filename = (string)parobj[2];
                try
                {
                    ClientSocket.EndConnect(ar);
                }
                catch (Exception ex)
                {
                    if (Error != null)
                    {
                        Error(ex, null);
                        return;
                    }
                    else
                    {
                        throw ex;
                    }
                }
                Server = new TcpSocketEventArgs(SC, OnDisConnected, OnReceive, OnUIInvoke, OnLimitSleep, OnError,
                                                ReceiveBufferSize, SendBufferSize, ClientSocket, sign);
                ServerList.Add(Server);
                Server.FileName = filename;
                OnLimitSleep();
                OnConnected(Server);
                Server.Receive();
            }
            else
            {
                try
                {
                    ClientSocket.EndConnect(ar);
                }
                catch (Exception ex)
                {
                    if (Error != null)
                    {
                        Error(ex, null);
                        return;
                    }
                    else
                    {
                        throw ex;
                    }
                }
                Server = new TcpSocketEventArgs(SC, OnDisConnected, OnReceive, OnUIInvoke, OnLimitSleep, OnError,
                                                ReceiveBufferSize, SendBufferSize, ClientSocket, sign);
                ServerList.Add(Server);
                OnLimitSleep();
                OnConnected(Server);
                Server.Receive();
            }
        }
Exemplo n.º 5
0
 private void OnDisConnected(TcpSocketEventArgs value)
 {
     RemoveClient(value);
     if (DisConnected != null)
     {
         DisConnected(this, value);
     }
 }
Exemplo n.º 6
0
 private void OnUIInvoke(object value)
 {
     if (UIInvoke != null)
     {
         object[]           parobject = (object[])value;
         TcpSocketEventArgs client    = (TcpSocketEventArgs)parobject[2];
         UIInvoke(this, (ushort)parobject[0], parobject[1], client);
     }
 }
Exemplo n.º 7
0
 protected override void Dispose(bool disposing)
 {
     if (Releaserbool)
     {
         Releaserbool = false;
         if (disposing)
         {
         }
         TcpSocketEventArgs[] Servers = new TcpSocketEventArgs[ServerList.Count];
         ServerList.CopyTo(Servers);
         foreach (TcpSocketEventArgs e in Servers)
         {
             e.Dispose();
         }
         base.Dispose(disposing);
     }
 }
Exemplo n.º 8
0
 private void AcceptCallBack(IAsyncResult ar)
 {
     if (Listenbool)
     {
         Socket ClientSocket;
         try
         {
             ClientSocket = ServerSocket.EndAccept(ar);
         }
         catch (Exception ex)
         {
             if (Error != null)
             {
                 Error(ex, null);
                 return;
             }
             else
             {
                 throw ex;
             }
         }
         TcpSocketEventArgs cl = new TcpSocketEventArgs(SC, OnDisConnected, OnReceive,
                                                        OnUIInvoke, OnLimitSleep, OnError, ReceiveBufferSize, SendBufferSize, ClientSocket);
         ClientList.Add(cl);
         OnConnected(cl);
         try
         {
             ServerSocket.BeginAccept(AcceptCallBack, null);
         }
         catch (Exception ex)
         {
             if (Error != null)
             {
                 Error(ex, null);
                 return;
             }
             else
             {
                 throw ex;
             }
         }
         cl.Receive();
     }
 }
Exemplo n.º 9
0
 protected override void Dispose(bool disposing)
 {
     if (Releaserbool)
     {
         Releaserbool = false;
         Listenbool   = false;
         if (disposing)
         {
         }
         TcpSocketEventArgs[] Clients = new TcpSocketEventArgs[ClientList.Count];
         ClientList.CopyTo(Clients);
         foreach (TcpSocketEventArgs e in Clients)
         {
             e.Dispose();
         }
         if (ServerSocket != null)
         {
             ServerSocket.Close();
             ServerSocket = null;
         }
         base.Dispose(disposing);
     }
 }
Exemplo n.º 10
0
 private void RemoveClient(TcpSocketEventArgs client)
 {
     ClientList.Remove(client);
 }
Exemplo n.º 11
0
 private void RemoveServer(TcpSocketEventArgs ser)
 {
     ServerList.Remove(ser);
 }