override public void OnMessageReceived(SocketBase.IConnection connection, SocketBase.MessageReceivedEventArgs e) { base.OnMessageReceived(connection, e); int readlength; TMessage message = null; try { message = this._protocol.Parse(connection, e.Buffer, this._maxMessageSize, out readlength); } catch (Exception ex) { this.OnConnectionError(connection, ex); connection.BeginDisconnect(ex); e.SetReadlength(e.Buffer.Count); return; } if (message != null) { this._socketService.OnReceived(connection, message); } e.SetReadlength(readlength); }
/// <summary> /// OnMessageReceived /// </summary> /// <param name="connection"></param> /// <param name="e"></param> protected override void OnMessageReceived(SocketBase.IConnection connection, SocketBase.MessageReceivedEventArgs e) { base.OnMessageReceived(connection, e); int readlength; TCommandInfo cmdInfo = null; try { cmdInfo = this._protocol.FindCommandInfo(connection, e.Buffer, this._maxMessageSize, out readlength); } catch (Exception ex) { this.OnError(connection, ex); connection.BeginDisconnect(ex); e.SetReadlength(e.Buffer.Count); return; } if (cmdInfo != null) { ThreadPool.QueueUserWorkItem(_ => { try { this._socketService.OnReceived(connection, cmdInfo); } catch { } }); } e.SetReadlength(readlength); }
/// <summary> /// OnMessageReceived /// </summary> /// <param name="connection"></param> /// <param name="e"></param> protected override void OnMessageReceived(SocketBase.IConnection connection, SocketBase.MessageReceivedEventArgs e) { base.OnMessageReceived(connection, e); //process message int readlength; TMessage message = null; try { message = this._protocol.Parse(connection, e.Buffer, out readlength); } catch (Exception ex) { base.OnConnectionError(connection, ex); connection.BeginDisconnect(ex); e.SetReadlength(e.Buffer.Count); return; } if (message != null) { Request <TMessage> request = null; if (this._receivingQueue.TryRemove(connection.ConnectionID, message.SeqID, out request)) { this.OnReceived(connection, request, message); } else { this.OnReceivedUnknowMessage(connection, message); } } //continue receiveing.. e.SetReadlength(readlength); }