Ejemplo n.º 1
0
        public WebSocketClient(bool noDelay, ILog logger)
            : base(logger)
        {
            _noDelay = noDelay;
            if (logger == null)
            {
                logger = LogManager.GetLogger(typeof(WebSocketClient));
            }
            _logger       = logger;
            _globalLogger = logger; // not such a big deal updating this because reference assignments are thread safe

            _conectionCloseWait = new ManualResetEvent(false);

            _frameBuilder              = new WebSocketFrameBuilder();
            _frameBuilder.OnClose     += FrameBuilder_OnClose;
            _frameBuilder.OnError     += FrameBuilder_OnError;
            _frameBuilder.OnPing      += FrameBuilder_OnPing;
            _frameBuilder.OnPong      += FrameBuilder_OnPong;
            _frameBuilder.OnTextFrame += FrameBuilder_OnTextFrame;
        }
Ejemplo n.º 2
0
        public WebSocketHandlerService(Stream stream, TcpClient tcpClient, string header, bool noDelay, ILog logger)
            : base(logger)
        {
            _stream    = stream;
            _header    = header;
            _logger    = logger;
            _tcpClient = tcpClient;

            // send requests immediately if true (needed for small low latency packets but not a long stream).
            // Basically, dont wait for the buffer to be full before before sending the packet
            tcpClient.NoDelay = noDelay;

            RemoteHost = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();
            RemotePort = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Port;
            LocalHost  = ((IPEndPoint)tcpClient.Client.LocalEndPoint).Address.ToString();
            LocalPort  = ((IPEndPoint)tcpClient.Client.LocalEndPoint).Port;

            _frameBuilder              = new WebSocketFrameBuilder();
            _frameBuilder.OnClose     += FrameBuilder_OnClose;
            _frameBuilder.OnError     += FrameBuilder_OnError;
            _frameBuilder.OnPing      += FrameBuilder_OnPing;
            _frameBuilder.OnPong      += FrameBuilder_OnPong;
            _frameBuilder.OnTextFrame += FrameBuilder_OnTextFrame;
        }