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(); } }
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(); } }