/// <summary> /// 消息传输信道 /// </summary> /// <param name="rawChannel">数据流信道</param> /// <param name="protocolStack">协议栈</param> /// <param name="parser">解析器</param> /// <exception cref="ArgumentNullException">参数错误</exception> public MessageTransportChannel(IRawTransportChannel rawChannel, IProtocolStack protocolStack, ISegmentDataParser <T> parser) { if (rawChannel == null) { throw new ArgumentNullException("rawChannel"); } if (protocolStack == null) { throw new ArgumentNullException("protocolStack"); } if (rawChannel.SupportSegment && parser == null) { throw new ArgumentNullException("parser"); } _rawChannel = rawChannel; _channelType = _rawChannel.ChannelType; //initialize segment data parser, if current channel support segment data recv. if (_rawChannel.SupportSegment) { _parser = parser; _parser.ParseSucceed += SegmentParseSucceed; _rawChannel.ReceivedDataSegment += ReceivedDataSegment; } else { _rawChannel.ReceivedData += RawReceivedData; if (_rawChannel.Buffer == null) { _rawChannel.Buffer = new ReceiveBuffer(ChannelConst.RecvBufferSize); } } _protocolStack = protocolStack; _rawChannel.Opened += Opened; _rawChannel.Opening += Opening; _rawChannel.Closed += Closed; _rawChannel.Closing += Closing; _rawChannel.Faulted += Faulted; _rawChannel.Disconnected += RawChannelDisconnected; _rawChannel.Connected += Connected; _key = _rawChannel.Key; _localIep = _rawChannel.LocalEndPoint; _remoteIep = _rawChannel.RemoteEndPoint; //open this channel at last. _rawChannel.Open(); }
/// <summary> /// 打开 /// </summary> public void Open() { _rawChannel.Open(); }