AppServer.NewRequestReceived 事件不会在 SuperSocket 中触发

AppServer.NewRequestReceived event doesn't fire in SuperSocket

我创建了一个服务器,只要收到新请求就打印一行:

var server = new AppServer();
if (!server.Setup(2012) || !server.Start()) {
    return;
}
server.NewSessionConnected += (session) => Console.WriteLine("new connection");
server.NewRequestReceived += (session, requestInfo) => Console.WriteLine("new request");

我从 netcat 连接到它:

C:\Users\sashoalm>nc localhost 2012
test
test
^C
C:\Users\sashoalm>

它打印 new connection 但从不打印 new request,尽管从 netcat 输入了 2 行。我知道每次输入整行时 netcat 都会将文本发送到服务器(这就是 netcat 的工作方式)。

编辑: 我发现另一个(措辞不太好)未回答的问题可能问的是同样的问题 - How to send data to server using supersocket library,但我不完全确定是否这是同样的问题。那里的人似乎试图从代码发送数据。

另一个相关问题 - 。他们在那里谈论协议。 SuperSocket 中没有指定协议时是否有默认协议?是 HTTP 还是其他?

下面使用一个简单的客户端,基于此MSDN Sample

    static void Main(string[] args)
    {
        IPHostEntry ipHostInfo = Dns.Resolve("localhost");
        IPAddress ipAddress = ipHostInfo.AddressList[0];
        IPEndPoint remoteEP = new IPEndPoint(ipAddress, 2012);

        Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        sender.Connect(remoteEP);

        Console.WriteLine("Socket connected to {0}", sender.RemoteEndPoint.ToString());

        List<string> list = new List<string>
            {
                "Test1\r\n",
                "Test2",
                "Test3\r\n",
                "Test4\r\n",
                "Test5\r\n",
                "Test6\r\n",
                "Test7",
                "Test8\r\n",
                "Test9\r\n",
            };

        foreach (string s in list)
            sender.Send(Encoding.ASCII.GetBytes(s));

        sender.Shutdown(SocketShutdown.Both);
        sender.Close();
    }

并使用稍微修改过的服务器版本:

    static void Main(string[] args)
    {
        var server = new AppServer();

        if (!server.Setup(2012) || !server.Start())
        {
            return;
        }

        server.NewSessionConnected += (session) => Console.WriteLine("new connection");
        server.NewRequestReceived += (session, requestInfo) => Console.WriteLine("new request: Key={0}", requestInfo.Key);

        Console.WriteLine("Press ENTER to exit....");
        Console.ReadLine();
    }

显示是否使用\r\n作为请求的终止符的效果:

Press ENTER to exit.... 
new connection 
new request: Key=Test1 
new request: Key=Test2Test3 
new request: Key=Test4 
new request: Key=Test5
new request: Key=Test6 
new request: Key=Test7Test8 
new request: Key=Test9

没有终止符的请求与下一个请求连接,直到找到终止符。