异步服务器套接字多个客户端多个、客户端、服务器

2023-09-02 20:43:38 作者:身未动,心已远°

我一直在与公布在MSDN上以下code:

I have been working with the following code published on msdn:

http://msdn.microsoft.com/en-us/library/fx6588te.aspx

据我所知,服务器应用程序不会被阻止,而该应用程序正在等待新的客户。

I understand that the server application is not blocked whilst the application is waiting for new clients.

不过可以在此应用程序(甚至插座)为此事处理多个并发请求?

However can this application (or even sockets) for that matter handle multiple concurrent requests?

如果客户A和B连接的同时,会发​​生什么?

What would happen if client A and B connected at the same time?

如果客户端A连接和其要求的处理需要5秒,如果客户端B连接一秒钟后它必须等待客户端A完成之前,其处理可以启动?

If client A connects and the handling of its request takes 5 seconds, if client B connects a second later must it wait for client A to finish before its processing can start?

或将客户A和客户B的请求,可以同时处理?

Or will client A and client B's requests be handled concurrently?

我已经通过把Thread.sleep代码做这个了一些测试(N)命令在监听套接字code接收/发送数据之间。然后我就可以发送多个请求到插座,他们似乎要处理。然而,插座总是处理它们的一样的线程ID - 这使我相信,它不是实际发生的事情兼

I have done some testing with this by putting Thread.Sleep(n) commands in between the receive/send data in the socket listener code. I can then send multiple requests to the socket and they appear to be handled. However the socket always handles them on the same thread id - which makes me believe that it isnt actually happening concurrently.

特别给出的描述微软提供的这个程序只是犯规块,同时等待新的连接 - 这是否意味着它的可以的处理并发连接

Especially given the description by microsoft that this app simply doesnt block whilst awaiting for new connections - does that mean it can handle concurrent connections?

推荐答案

[更新2014年]:看来这个例子已被修改,因为这个答案被张贴,作为的