日期:2014-05-17 浏览次数:20940 次
private void BeginReceive() { try { StateObject so = new StateObject(this.mSocket); mSocket.BeginReceive(so.Buffer, Session.OFFSET, so.Buffer.Length, SocketFlags.None, this.ReceiveCallBack, so); } catch (Exception ex) { TriggerErrorEvent(ex); } } private void ReceiveCallBack(IAsyncResult result) { try { StateObject so = (StateObject)result.AsyncState; int dataLength = so.Socket.EndReceive(result); Logger.Debug(string.Format("Read Message Successed, SessionID:{0} Count {1}", this.SessionID, this.mReadCount++)); so.Socket.BeginReceive(so.Buffer, Session.OFFSET, so.Buffer.Length, SocketFlags.None, this.ReceiveCallBack, so); } catch (Exception ex) { TriggerErrorEvent(ex); } }
private void ReceiveCallBack(IAsyncResult result) { try { StateObject so = (StateObject)result.AsyncState; int dataLength = so.Socket.EndReceive(result); if (dataLength > 0) { Logger.Debug(string.Format("Read Message Successed, SessionID:{0} Count {1}", this.SessionID, this.mReadCount++)); so.Socket.BeginReceive(so.Buffer, Session.OFFSET, so.Buffer.Length, SocketFlags.None, this.ReceiveCallBack, so); } } catch (Exception ex) { TriggerErrorEvent(ex); } }