예제 #1
0
        private void sendResponse()
        {
            logger.Debug("{0} send response", _connectionToken.Substring(0, 6));

            //send response
            _workStatus = SessionWorkStatus.SendingResponseHeader;

            //append connection header if need
            if (_clientKeepAlive && !_serverKeepAlive)
            {
                _lastResponseHeader.Connection = "close";
            }

            if (_lastProcessor.ResponseBodyLength > 0)
            {
                //send response with body
                _session.Send(_lastResponseHeader, _lastProcessor.ResponseBodyLength);
            }
            else if (_lastProcessor.ResponseBodyLength == 0)
            {
                //send response header only
                _session.Send(_lastResponseHeader);
            }
            else
            {
                //NOTE::
                //send response in "chunked" transfer encoding mode(with unknow body length)
                _session.Send(_lastResponseHeader, long.MaxValue);
            }
        }
예제 #2
0
    private static void Server_NewClientAccepted(Socket client, ISocketSession session)
    {
        Console.WriteLine("----- new client ------------");
        AsyncSocketSession ass = session as AsyncSocketSession;

        ass.SetReceiveHandler(arg =>
        {
            Console.WriteLine("----- new receive ------------");
            string received = System.Text.Encoding.UTF8.GetString(arg.Buffer, arg.Offset, arg.BytesTransferred);
            Console.WriteLine(received);

            ass.Send(received);
        });
    }
예제 #3
0
    private static void Server_ReadCompleted(Socket client, object state)
    {
        SocketAsyncEventArgs arg = state as SocketAsyncEventArgs;

        string received = System.Text.Encoding.UTF8.GetString(arg.Buffer, arg.Offset, arg.BytesTransferred);

        Console.WriteLine(received);

        AsyncSocketSession session = arg.UserToken as AsyncSocketSession;

        if (session == null)
        {
            return;
        }
        session.Send(received);
    }