one server multiple clients

后端 未结 4 2021
小鲜肉
小鲜肉 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:29

    Thanks BTW: sorry for confusing every one, it is a small project that only involve 5-10 classes.

    There's definately nothing wrong with it. All higher level abstractions are based on sockets one way or another. Unless your project is sufficiently large there is no need to pull a series other frameworks/toolkit to perform the same job. Threads are cheap (and can even benefit from a multicore architecture), although using SelectableChannels as @aioobe suggested is not a bad idea either.

    When your projects require it, you can always learn about other inter-process communication methods (message passing, remote method invocaton etc., and its about 100 implementations) then.

    You might however want to limit the number of threads you server use simultaneously. This can easily be achieved by claiming e.g., a semaphore of a size equal to the number of threads you want to serve. Another interesting thing to consider is using java thread pools to better reuse your resources.

提交回复
热议问题