public void DisconnectSocket() { if (this._ClientSocket != null) { TCPEventArgs args = new TCPEventArgs(null, this._ID, this._ClientSocket.RemoteEndPoint); try { if (this._ClientSocket.Connected) { this._ID = -1; this._ClientSocket.Shutdown(SocketShutdown.Both); System.Threading.Thread.Sleep(10); this._ClientSocket.Close(); this._ClientSocket = null; } } catch (Exception ex) { SocketHelper.ShowError(this, ex); } if (BeginDisconnect != null) { BeginDisconnect(this, args); } } }
/// <summary> /// Socket Read Event /// </summary> private void ReadSocket(object sender, TCPEventArgs e) { if (BeginRead != null) { BeginRead(this, e); } }
/// <summary> /// Disconnect /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DisconnectSocket(object sender, TCPEventArgs e) { this.TCPClients[e.SocketID] = null; --this.ConnectionCount; if (BeginDisconnect != null) { BeginDisconnect(this, e); } }