one server multiple clients

后端 未结 4 2029
小鲜肉
小鲜肉 2021-01-22 08:57

I am engaging the following problems:

  1. I need to write a server program, will accept multiple clients
  2. all clients are subscribing the same data from server
4条回答
  •  再見小時候
    2021-01-22 09:16

    is it necessary to have a thread for each client socket?

    No, as a matter of fact, I wouldn't even not recommend it. If it's a small project and you don't want to use any existing library, I would suggest you use the java.nio package and the SelectableChannels. With a so called selector you can easily monitor clients for incoming data in a non-blocking way.

    Here are a few useful links:

    • NIO Examples (from the official tutorial)
    • The Rox Java NIO Tutorial

提交回复
热议问题