/// <summary> /// 关闭连接 /// </summary> public void Close() { if (this.State != ConnectionState.Closed && driver != null) { //扔回连接池中 var currentSettings = new WebCrawlerConnection { Address = this.IPAddress, Port = this.Port }; SoapTcpPool pool = SoapTcpPool.GetPool(currentSettings); if (null != pool) { pool.ReleaseToPool(this.driver); this.driver = null; } else { this.driver.Close();//如果没有在池中 那么直接关闭对象 } } }
/// <summary> /// 打开连接 /// </summary> public void Open() { if (null != this.driver && State == ConnectionState.Open) { return; } try { var currentSettings = new WebCrawlerConnection { Address = this.IPAddress, Port = this.Port, TimeOut = this.TimeOut, Pooling = this.Pooling, PoolingMinSize = this.PoolingMinSize, PoolingMaxSize = this.PoolingMaxSize, }; SoapTcpPool pool = SoapTcpPool.GetPool(currentSettings); if (null != pool) { driver = pool.GetConnection(); } if (driver == null) { driver = SoapTcpPool.CreatNewConnection(this.IPAddress, this.Port, this.Pooling, this.PoolingMinSize); } if (!driver.Connected) { driver.Connect(this.TimeOut * 1000); } this.State = ConnectionState.Open; } catch (Exception ex) { this.State = ConnectionState.Closed; throw ex; } }