示例#1
0
 public RiverServerConnection(RiverServer server, TcpClient client)
 {
     Trace.WriteLine("River connection from: " + client.Client.RemoteEndPoint);
     _server       = server;
     _client       = client;
     _clientStream = _client.GetStream();
     _clientStream.BeginRead(_readBuffer, 0, _readBuffer.Length, ReceivedInitiationFromClient, null);
 }
示例#2
0
文件: Handler.cs 项目: lanicon/river
        /*
         * public void SwitchFrom(Handler handler, RiverServer server, ReStream stream)
         * {
         *      if (handler is null)
         *      {
         *              throw new ArgumentNullException(nameof(handler));
         *      }
         *
         *      if (server is null)
         *      {
         *              throw new ArgumentNullException(nameof(server));
         *      }
         *
         *      if (stream is null)
         *      {
         *              throw new ArgumentNullException(nameof(stream));
         *      }
         *
         *      // you must be sure that previous readers is readed and that is not subscribed yet!!
         *      // you must be sure there is no forward connection already established
         *      // you must be sure that previous handler did not sent any response to client yet!!
         *
         *      // init
         *      stream.ResetReader();
         *      Init(server ?? handler.Server, handler.Client, stream);
         *
         *
         *      // copy fields
         *      // _buffer = handler._buffer;
         *      // _bufferReceivedCount = handler._bufferReceivedCount;
         *
         *      // Client = handler.Client;
         *      // Server = server ?? handler.Server;
         *      // Stream = handler.Stream; // what about stream wrapper? like http wrap
         *
         *      // re-handshake
         *      // HandshakeHandler();
         * }
         */

        public void Init(RiverServer server, TcpClient client, Stream stream = null)
        {
            Server = server ?? throw new ArgumentNullException(nameof(server));
            Client = client ?? throw new ArgumentNullException(nameof(client));

            // disable Nagle, carefully do write operations to prevent extra TCP transfers
            // efficient write should contain complete packet for corresponding protocol
            Client.Client.NoDelay = true;

            Stream = WrapStream(stream ?? Client.GetStream2());

            BeginSourceReader();
            ReadMoreHandshake();
        }
示例#3
0
文件: Handler.cs 项目: lanicon/river
 public Handler(RiverServer server, TcpClient client)
     : this()
 {
     Init(server, client);
 }