public void Set(EnumConnectionEventType t, ExSocket e, byte[] d, int l) { EventType = t; Exsocket = e; Message = d; PrtcId = 0; }
public void Release() { CloseSocket(); _CachedSendMessageQueue.Clear(); _ConEventArgsQueue.Clear(); _BufferBlock = null; if (_SyncSendMessageThread != null) { //_SyncSendMessageThread.Interrupt(); _SyncSendMessageThread.Abort(); _SyncSendMessageThread = null; } if (_ConnectTimer != null) { _ConnectTimer.Stop(); _ConnectTimer.Close(); } _ServiceSocket = null; _DataToken = null; }
private void CloseSocket() { var cea = _ConnectionEventArgsPool.GetObject(); cea.Set(EnumConnectionEventType.close, _ServiceSocket, null, 0); _ConEventArgsQueue.Enqueue(cea); if (_ServiceSocket != null) { _ServiceSocket.Close(); _ServiceSocket = null; } if (_DataToken != null) { _DataToken.Reset(true); } if (_SAEA4Connect != null) { _SAEA4Connect.Dispose(); _SAEA4Connect = null; } if (_SAEA4Recv != null) { _SAEA4Recv.Dispose(); _SAEA4Recv = null; } }
public virtual void OnReceiveMessage(ExSocket exSocket, byte[] data) { if (HandleReceivedMessage != null) { HandleReceivedMessage(exSocket, data); } }
public void Connect(string ipStr, int port) { _CachedSendMessageQueue.Clear(); _ConEventArgsQueue.Clear(); _RemoteEndPoint = new IPEndPoint(IPAddress.Parse(ipStr), port); if (_ServiceSocket != null) { _ServiceSocket.Close(); _ServiceSocket = null; } _ServiceSocket = new ExSocket(_RemoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (_SAEA4Connect != null) { _SAEA4Connect.Dispose(); _SAEA4Connect = null; } _SAEA4Connect = new SocketAsyncEventArgs { RemoteEndPoint = _RemoteEndPoint }; _SAEA4Connect.Completed += OnConnectedCompleted; try { if (!_ServiceSocket.ConnectAsync(_SAEA4Connect)) { ProcessConnect(_SAEA4Connect); } if (_ConnectTimer != null) { _ConnectTimer.Close(); } _ConnectTimer = new System.Timers.Timer(CONNECT_TIME_OUT); _ConnectTimer.AutoReset = false; _ConnectTimer.Enabled = true; _ConnectTimer.Elapsed += new System.Timers.ElapsedEventHandler((object source, System.Timers.ElapsedEventArgs e) => { if (_ServiceSocket != null && !_ServiceSocket.Connected) { _ServiceSocket.Close(); _ServiceSocket = null; var cea = _ConnectionEventArgsPool.GetObject(); cea.Set(EnumConnectionEventType.connect_failed, null, null, 0); _ConEventArgsQueue.Enqueue(cea); } }); } catch (Exception ex) { HobaDebuger.Log(HobaText.Format("Connect Failed: {0}", ex.Message)); } if (_SyncSendMessageThread != null) { _SyncSendMessageThread.Abort(); _SyncSendMessageThread = null; } _SyncSendMessageThread = new Thread(SendMessageLoop); _SyncSendMessageThread.Start(); }
public virtual void OnProtocolError(ExSocket exSocket) { }