Results 1 to 6 of 6
  1. #1
    burrough is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default Synchronous client behavior on a network

    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 all 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!

  2. #2
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    How would you ensure when all messages arrive? You can't prevent a network issue or network lag. What exactly are you trying to do that critically needs all clients to be synchronized?

  3. #3
    burrough is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by ra4king View Post
    How would you ensure when all messages arrive? You can't prevent a network issue or network lag. What exactly are you trying to do that critically needs all clients to be synchronized?
    On a second thought, I realize that it may be impossible to completely synchronize the clients on a network, due to the nature of communication on a network.

    However, is there a way to at least minimise the difference in starting times among the clients from a programming point of view, or this is very much down to the network condition?

    Most importantly, the server must synchronize the clients across rounds/tasks, i.e. the server should only issue a new message after receiving all the responses from the clients from the current round/task. I wonder what is the correct way of doing this?

    Thanks.

  4. #4
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    What is so hard about having the server wait until all messages are received? ;)

  5. #5
    burrough is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by ra4king View Post
    What is so hard about having the server wait until all messages are received? ;)
    Can I do this with a bunch of boolean variables on the server side, one for each message from a client? I wonder what is the standard practice for this, since I am very much new to network programming in Java. Thanks.

  6. #6
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Or you can have a variable that acts like a backwards counter. It holds the number of clients connected and subtracts 1 as each message comes in. When it gets to 0, the server can then do the next job.

Similar Threads

  1. Need help with synchronous painting
    By JavaRulez in forum Advanced Java
    Replies: 7
    Last Post: 05-09-2010, 09:34 AM
  2. Replies: 7
    Last Post: 05-02-2010, 11:35 PM
  3. different behavior between debug and run
    By flaquitqm in forum Eclipse
    Replies: 1
    Last Post: 03-04-2010, 04:01 PM
  4. Java Crossplatform Behavior
    By wdavis in forum New To Java
    Replies: 2
    Last Post: 11-05-2009, 02:22 PM
  5. htmlparser inconsistent behavior
    By sjchase in forum Advanced Java
    Replies: 0
    Last Post: 07-22-2009, 12:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •