开发者

Connecting multiple clients to server

I am relatively new to server programming and have this basic question.

When a server is established and number of clients are connecting , how do we handle multiple clients ...?

Do we create threads at the server开发者_高级运维 and assign each client one of them ??

Some sample code and links that help me read about this are very helpful.


You need to accept connections sequentially. However, you can assign a different thread to each client connection in order to serve them simultaneously.

Take a look at: A multi-threaded socket-based server


If you plan to serve only few connections, you could create separate thread for each connection. But if you plan to serve more connection you should see at asynchronous socket programming

Google for java.nio and async sockets programming. http://www.gamedev.net/reference/programming/features/asyncsock/ Asynchronous IO in Java?

(As a .Net developper I also can recommend you to read this msdn article just to understand main principles of async socket programming)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜