Пример #1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="clientStub"></param>
 /// <param name="serviceType"></param>
 internal TCPClient(ClientStub clientStub, Type serviceType) : base(clientStub, serviceType)
 {
     _responseWaits = new ResponseWaits(RequestTimeoutSeconds);
     _bootstrap     = new Bootstrap()
                      .Group(new MultithreadEventLoopGroup())
                      .Channel <TcpSocketChannel>()
                      .Option(ChannelOption.TcpNodelay, true)
                      .Handler(new ActionChannelInitializer <ISocketChannel>(channel =>
     {
         IChannelPipeline pipeline = channel.Pipeline;
         pipeline.AddLast("framing-enc", new LengthFieldPrepender(2));
         //数据包最大长度
         pipeline.AddLast("framing-dec", new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2));
         ClientHandler clientHandler = new ClientHandler(_responseWaits)
         {
             OnDeserializeMessage = DeserializeMessage
         };
         pipeline.AddLast(clientHandler);
     }));
 }
Пример #2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="responseWaits">响应池</param>
 public ClientHandler(ResponseWaits responseWaits)
 {
     _responseWaits = responseWaits;
 }