1

I've set up sockets for communication between a server and client and have threads running on the server for multiple client connections. Furthermore I'm now sending byte arrays between server and client for data however I'm thinking of implementing cyclic barriers to make the server wait for a specific number of clients to connect before a different message is sent to each client.

This communication and waiting will need to be ongoing for example once this threshold of client connections is made and the message sent out, the server should now wait again for a message to come back from each client, probably a different message. This should continue for a few iterations at least, I'm wondering if I implement cyclic barriers for this process would i go be finding the best solution to this process?

Is this the intended use of cyclic barriers or would there be a better alternative to my idea?

To keep it simple, I intend to wait for 2 clients to connect. There will also be timeout conditions enforced to deal with possible failure.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Unless I'm misunderstanding something, I think that forcing sockets to wait for a specific number of clients to connect would not be good. One example is if, for some reason, one of the sockets that should have connected can't connect (network outage, computer crashed, etc.). This leaves the rest of the sockets in an unknown state. Even if, after one second, you get your number of clients, the users will notice this wait. – NomadMaker Apr 10 '20 at 16:12
  • This is a good point, do you know how i would implement a solution to failure? This can be put in place for now but for the time being lets say all clients can connect 100% of the time, of course I know this would not be real world but im new to network programming and just trying out different things. – Dylan Maguire Apr 10 '20 at 18:02
  • If you're new, I'd suggest starting out as simply as possible. Anything new is just one more thing to break, no matter how interesting it is. Also, I'm an old programmer - I tend to think more in terms of failures than in 100% successes. – NomadMaker Apr 10 '20 at 18:19
  • This is the point i have gotten to in my learning of java networking although my underlying knowledge may not be sound, it is time to learn these new things in a way which i can understand them hence the long-winded question. I guess for failures I can implement failure conditions but that is not my current problem, one I will address when I know how to. – Dylan Maguire Apr 10 '20 at 19:28

0 Answers0