public void Connect(string url) { this.Dispose(); this.closing = false; string urlInfo = url.TrimStart(("tcp://").ToCharArray()); string[] infos = urlInfo.Split(':'); tcpsocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); tcpsocket.BeginConnect(infos[0], int.Parse(infos[1]), (ar) => { try { this.tcpsocket.EndConnect(ar); } catch (Exception e) { this.OnError(errors.New(e.Message)); return; } this.doHandShake(""); this.eventListener.OnConn(); this.rcvbuf = new TcpBuffer(new byte[8192]); this.PostReceive(); this.ping = new AutoPing(this, this.eventListener); }, null); }
public void Dispose() { if (this.tcpsocket != null) { this.tcpsocket.Close(); this.tcpsocket = null; this.rcvbuf.Dispose(); this.rcvbuf = null; this.msgQueue.Clear(); this.ping = null; } }