Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock DataArrival problem

Status
Not open for further replies.

mibosoft

Programmer
Jul 23, 2002
106
SE
Hi,
I have integrated a winsock server in my app and works fine as long as complete data packages are received. The server is based on a famous example (I think):

The problem is how to determine that received data is complete. The wiki example solves it by adding a end-of-transmission sign in alla sent data. In the same way, received data isn't computed until the EOT sign is reached.

++++++++++++snip

PROCEDURE DataArrival
LPARAMETERS tnByteCount
LOCAL lcBuffer
lcBuffer = SPACE(tnByteCount)

* This gets the data from the socket. It can happen, that the data isn't
* received in a single rush. Thus we need a EOT (end of transmission)
* sign to be sure, the data is complete. Until we get this, the data
* is stuffed into cReceiveBuffer.

This.GetData( @lcBuffer, , tnByteCount )
IF AT( EOT, lcBuffer ) = 0 && Not yet finished
This.cReceiveBuffer = This.cReceiveBuffer + lcBuffer
ELSE
This.cReceiveBuffer = This.cReceiveBuffer + LEFT( lcBuffer, AT( EOT, lcBuffer ) -1 )

...

++++++++++++snip

The data I want to receive comes from a POST action in a web browser form. How can I determine (in the DataArrival event) that all data has been received? Any hints are welcome.

Thanks'
Micael
 
That's the thing about TCP/IP. You have basically three options:
Wait for an EOT character
Wait for a timeout period
Know in advance how long the message will be

The host's responsibility ends with receiving messages. There's nothing built into the protocol to tell it how long a message will be, only that the message it received got there in one piece. Different senders may have their output buffers set to different lengths.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
I always send the size of the message as the first 10 bytes of the message. Then you know what to wait for.

I would be careful using some sort of EOT character especially if you messages contain binary data.

Andy
 
Thanks' for your answers. What I do now is to check for a certain string, always present at the end of the message, before closing the connection. This seems to work fine.
/Micael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top