public void Disconnect() { if (netWorkState == NetWorkState.DISCONNECTED) { return; } /// Force update to make sure all received messages been dispatched. Update(); // free managed resources if (_protocol != null) { _protocol.close(); } try { this._socket.Shutdown(SocketShutdown.Both); this._socket.Close(); this._socket = null; } catch (Exception e) { _onError(e.Message); } netWorkState = NetWorkState.DISCONNECTED; _eventManager.ClearCallBackMap(); _eventManager.ClearCallBackMap(); _reqId = 100; }
public void Disconnect() { if (netWorkState == NetWorkState.DISCONNECTED) { return; } /// Force update to make sure all received messages been dispatched. Update(); // free managed resources if (_protocol != null) { _protocol.close(); } try { _socket.Shutdown(SocketShutdown.Both); _socket.Close(); _socket = null; } catch (Exception) { //todo : 有待确定这里是否会出现异常,这里是参考之前官方github上pull request。emptyMsg } netWorkState = NetWorkState.DISCONNECTED; _eventManager.ClearCallBackMap(); _eventManager.ClearCallBackMap(); _reqId = 100; }
public void sendHeartBeat(object source, ElapsedEventArgs e) { TimeSpan span = DateTime.Now - lastTime; timeout = (int)span.TotalMilliseconds; //check timeout if (timeout > interval * 2) { //protocol.getPomeloClient().disconnect(); protocol.close(); //stop(); return; } //Send heart beat protocol.send(PackageType.PKG_HEARTBEAT); }
public void Disconnect(PackageType type) { if (netWorkState == NetWorkState.DISCONNECTED) { return; } /// Force update to make sure all received messages been dispatched. Update(); // free managed resources if (_protocol != null) { _protocol.close(); } try { _socket.Shutdown(SocketShutdown.Both); _socket.Close(); _socket = null; } catch (Exception) { //todo : 有待确定这里是否会出现异常,这里是参考之前官方github上pull request。emptyMsg } netWorkState = NetWorkState.DISCONNECTED; _eventManager.ClearCallBackMap(); _eventManager.ClearCallBackMap(); //网络关闭会触发这个断开 if (PackageType.PKG_NONE != type) { if (PackageType.PKG_KICK == type) { _onError("kick by server"); } else if (PackageType.PKG_HEARTBEAT == type) { _onError("network is down"); } } }