Пример #1
0
        public Listener(IPAddress ipAddress, int port, ReponseHandler reponseHandler = null)
        {
            ReponseHandler = reponseHandler;
            IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _socket.Bind(localEndPoint);
            _socket.Listen(SocketBacklog);
            _listenTask = Task.Run(Listen);
        }
        public RequestsHandler(Socket socket, ReponseHandler reponseHandler)
        {
            this._reponseHandler = reponseHandler;
            var networkStream = new NetworkStream(socket, true)
            {
                ReadTimeout  = NetworkStreamTimeout,
                WriteTimeout = NetworkStreamTimeout
            };

            _streamReader = new StreamReader(networkStream);
            _response     = new Response(networkStream);
        }