Results 1 to 8 of 8
  1. #1
    krishforever is offline Member
    Join Date
    Jan 2011
    Posts
    19
    Rep Power
    0

    Smile how to handle data over two distinct socket connection

    hi everyone,

    What i need is creating a server and client and client should make two connections to the server.

    Then server send 4 numbers through two connections and client has to do some calculations and send back the answer two server.

    numbers can come randomly.that means one number can be come through one connection while others come through second connection.

    But I have to send the answer as soon as I got two numbers.How can I handle data which come from two connections?

    thanks.....

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default

    Who do you send the answer to?

  3. #3
    krishforever is offline Member
    Join Date
    Jan 2011
    Posts
    19
    Rep Power
    0

    Default

    when the clients get two numbers from any connection,then it has to caluculate and send the answer to server.

    My problem is when client gets numbers from two connections,how the program can decide when two numbers have arrived.How the client can keep the track of incoming data?

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    With a queue?

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default

    Agreed, a Queue. Even if you just had to variables it'd work - accepting a message from a client is a blocking operation, so it can even be done in sequence: (pseudocode)
    Java Code:
    while(true){
        number a = connection.read(); //wait until a client sends a message
        number b = connection.read(); //wait until any other client sends a message
        serverConnection.send(a+b); //Send the message once two numbers have been read
    }
    This is over simplified, but depending on how you set up your connection pool, this might just work. However, if you have many many clients all running through separate threads, then you'd want some kind of queue to deal with concurrency and multitude of connections.

  6. #6
    krishforever is offline Member
    Join Date
    Jan 2011
    Posts
    19
    Rep Power
    0

    Default

    Hi,
    thanks both.i ll try it.

  7. #7
    krishforever is offline Member
    Join Date
    Jan 2011
    Posts
    19
    Rep Power
    0

    Default

    hi,
    when i create two cconnections in the same client should I creat two input and output stram for those connnections?

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

Similar Threads

  1. How to handle socket Exception
    By mayank0512 in forum Networking
    Replies: 14
    Last Post: 12-21-2010, 11:31 PM
  2. Replies: 9
    Last Post: 08-25-2010, 07:31 AM
  3. Java.net.socket connection :connection closed
    By veeru541 in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2010, 02:14 AM
  4. Socket connection Problem
    By ighor10 in forum Networking
    Replies: 3
    Last Post: 06-23-2010, 04:10 AM
  5. Replies: 7
    Last Post: 02-11-2009, 09:14 PM

Posting Permissions

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