Multiple client connections from one process
With reference to socket programming, I am aware that a server can connect to multiple clients and process each client within开发者_如何学JAVA a seperate execution unit i.e thread. I would like to have these multiple clients within a single process. That is a process with multiple threads with each thread being seperate clients and connecting through different addresses with the server.
Is it ok to do this? During the course of execution, clients close(with the exit of its thread) and new clients connections are made. Would be gratefull for some code help or even a direction.
Thanks
It's ok to do that. Though, you are wasting resources and performance if the protocol provides a way to perform multiple asynchronous requests from a single connection.
About code direction, it all depends on what you want to achieve. Most simple setup would be to create a socket and connect to the server at the initialisation of each client thread. (And close the socket when the thread exits, as you mentioned.)
精彩评论