dcsimg
Results 1 to 3 of 3

Thread: Wait and receive all data before continue Socket Programming

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    7

    Wait and receive all data before continue Socket Programming

    Hi all,

    I have a question. I recently made a simple TCPServer and a TCPClient, both of them console applications. I can send data from client to server and from server to client normally, but when the data is more than lets say 10 lines the server/client gets the five of them at first and the second time with the next message it gets the rest.
    So I would like for the server/client to wait until the other server/client has finished sending all data before continue. I dont even know what to search in google for this so I need your help

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: Wait and receive all data before continue Socket Programming

    When you say "Wait" do you mean that you want to loop round waiting for the rest of the message ? That is never a good idea.

    When sending a message add some kind of EOT (End of Transmission) character to the end of the message. (EOT is actually an Ascii character, use that).

    I assume you are responding to message received events. In that case when you receive a message you can look to see if it's terminated with EOT and if it isn't then you simply store the data into a variable and exit the vent. Each time the event is teiggered you append the new data into the variable until you see the EOT and then you know you have the whole message.

    Using that method you can now send messages of any length and the receiver will always know when the message is complete.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    7

    Re: Wait and receive all data before continue Socket Programming

    I just want to "wait" until the client stops sending data.... I dont know what to search or what to do in order to solve this. I think many people have/had this problem.
    My server just goes on no matter if client still sends data, that's what I would like to handle...

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width