• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Synchronizing clients over a network

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I am relatively new to Java network programming, and would appreciate if anyone could point me to the right direction to the problem below:

A server S and three clients named A, B, and C respectively are on a network. A task is initiated by S, and is repeated for a number of times. For each run of the task, S sends a message to A, B, and C. Upon receiving the message, A, B and C are supposed to start their individual sub-tasks simultaneously, and finish working on the sub-tasks at the same time (this part can be controlled by a counter on the client side).

I am thinking S can broadcast the initial message to A, B, and C via sockets. However, how can we ensure that the clients A, B, and C all start at the same time (e.g. what if the message to A arrives slightly later than the ones to B and C because of some network issue?)

In addition, the clients will send some messages back to the server at end of each of their sub-tasks. So S should only initiate the next 'round' of communication after it receives all the messages from the clients in the current 'round'. I wonder how we can enforce such behavior.

Thanks!
 
Marshal
Posts: 28295
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Evan Yang wrote:Upon receiving the message, A, B and C are supposed to start their individual sub-tasks simultaneously, and finish working on the sub-tasks at the same time (this part can be controlled by a counter on the client side).


This is an extremely strange requirement. Start simultaneously? Finish at the same time? Why are those requirements? Why is it a problem if B starts a quarter of a second later than A and C?

I am thinking S can broadcast the initial message to A, B, and C via sockets. However, how can we ensure that the clients A, B, and C all start at the same time (e.g. what if the message to A arrives slightly later than the ones to B and C because of some network issue?)


You can't ensure that. There isn't even a way to monitor whether A, B, and C start at the same time, let alone enforce it.

In addition, the clients will send some messages back to the server at end of each of their sub-tasks. So S should only initiate the next 'round' of communication after it receives all the messages from the clients in the current 'round'. I wonder how we can enforce such behavior.


The server simply waits until it has received all of the messages. I'm not sure what you mean by "how we can enforce such behavior"... the simplest thing would be to have three boolean variables which record when each of the three messages have been received, for example. Was that the sort of question you meant that to be?
 
Evan Yang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Evan Yang wrote:Upon receiving the message, A, B and C are supposed to start their individual sub-tasks simultaneously, and finish working on the sub-tasks at the same time (this part can be controlled by a counter on the client side).


This is an extremely strange requirement. Start simultaneously? Finish at the same time? Why are those requirements? Why is it a problem if B starts a quarter of a second later than A and C?

Evan Yang wrote:I am thinking S can broadcast the initial message to A, B, and C via sockets. However, how can we ensure that the clients A, B, and C all start at the same time (e.g. what if the message to A arrives slightly later than the ones to B and C because of some network issue?)


You can't ensure that. There isn't even a way to monitor whether A, B, and C start at the same time, let alone enforce it.



Imagine the server S is the 'judge', and clients A, B and C are 'competitors' who compete to execute the same given task, and there is a time limit (say 30s) for them to do it, and their performance/quality of execution is recorded at the end of the 30s and sent back to S.

Ideally, once the server says 'START', then the 30s countdown on A, B, and C starts simultaneously. Now, I understand that the 'START' message may not arrive at A, B, and C simultaneously, and hence the agents may not all start at the same time. But is there any way we can keep the difference in start times as small as possible? For example, I wouldn't want C to start 20s after A and B have started.

Paul Clapham wrote:

Evan Yang wrote:In addition, the clients will send some messages back to the server at end of each of their sub-tasks. So S should only initiate the next 'round' of communication after it receives all the messages from the clients in the current 'round'. I wonder how we can enforce such behavior.


The server simply waits until it has received all of the messages. I'm not sure what you mean by "how we can enforce such behavior"... the simplest thing would be to have three boolean variables which record when each of the three messages have been received, for example. Was that the sort of question you meant that to be?



Yes, I just need a mechanism that makes sure the server has received all the results for the current round/task before moving on to the next one, as certain information from previous rounds/tasks are used in the future rounds/tasks.
 
Paul Clapham
Marshal
Posts: 28295
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You still seem to be hung up on "simultaneously". There's no such thing in the network world. There is no way for anything to tell whether two events on different computers are simultaneous and so the concept is meaningless. You can't even necessarily tell whether one event on computer A occurs before or after another event on computer B.

Now having said that, you could certainly work on the network to make sure that all three clients were configured the same way and that the network connections involved were all comparable. However note that none of that has anything to do with Java at all. It's all about network configuration.

As for your Java requirement (you want to make sure you have responses from all three computers), that's just basic Java programming.
 
Do not threaten THIS beaver! Not even with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic