////////////////////////////////////////////////////////////////////// // Connection accept an incoming connection protected virtual void AcceptFrom(Socket socket) { this.Input = new Global.Buffer(); this.Output = new Global.Buffer(); this.Socket = socket; OnConnected(); }
////////////////////////////////////////////////////////////////////// // Connection close public virtual void Disconnect() { lock (this) { if (this.Socket != null) { this.Socket.Close(); } this.Socket = null; } if (ReadIoOver != null) { ReadIoOver.AsyncWaitHandle.WaitOne(); } if (WriteIoOver != null) { WriteIoOver.AsyncWaitHandle.WaitOne(); } this.Input = this.Output = null; }
////////////////////////////////////////////////////////////////////// // Connection accept an incoming connection protected virtual void AcceptFrom(Socket socket) { this.Input = new Global.Buffer(); this.Output = new Global.Buffer(); this.Socket = socket; OnConnected(); }
////////////////////////////////////////////////////////////////////// // Connection close public virtual void Disconnect() { lock (this) { if (this.Socket != null) this.Socket.Close(); this.Socket = null; } if (ReadIoOver != null) ReadIoOver.AsyncWaitHandle.WaitOne(); if (WriteIoOver != null) WriteIoOver.AsyncWaitHandle.WaitOne(); this.Input = this.Output = null; }
////////////////////////////////////////////////////////////////////// // Connection connect to public virtual SocketError ConnectTo(IPAddress address, int port) { try { this.Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); this.Socket.Connect(address, port); this.Input = new Global.Buffer(); this.Output = new Global.Buffer(); return SocketError.Success; } catch (SocketException exception) { return (SocketError)exception.ErrorCode; } finally { this.Input = this.Output = null; } }