I am trying to communicate to a local AS3 Air app on my PC via sockets. The VB.Net app is acting as a server in this case while the Air app is a client.
The .Net app sends data every 25ms to the Air app. I have开发者_JAVA百科 not send any message termination. I just receive the data on Air app and process it.
On the receiving side when I debug the data I see that that some transitions have been concated.
Something like if I send "ABCDEF"
successively for most cases I do receive "ABCDEF"
however in some cases I receive "ABCDEFABCDEF"
Is it possible that the underlying TCP network is combining the data and then sending it as one packet.
Do I really need to send some message terminator for instance like this "ABCDEF$"
and then split my messages at the receiving end?
Am I goofing up big time?
From the documentation for Socket.Send:
There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
There's also no guarantee that you'll receive a complete message at the receiving end either - this is just how sockets work. I'd suggest adding an "End of message" marker, and looping in your receive code until you receive a complete message - but you may receive a buffer that straddles two messages, so when you've got an "End of message" marker, you need to keep hold of any data received after that point, for use in reconstructing the next message.
I.e. imagine that you have two messages to receive - "AAAAAA" and "BBBBBBBB". You might receive the following from three separate calls to Receive (after adding $ as an end of message marker):
AAAA
AAAA$BB
BBBBBB$
Can you set NoDelay
to True on the socket?
The Nagle algorithm is designed to reduce network traffic by causing the socket to buffer small packets and then combine and send them in one packet under certain circumstances. A TCP packet consists of 40 bytes of header plus the data being sent. When small packets of data are sent with TCP, the overhead resulting from the TCP header can become a significant part of the network traffic. On heavily loaded networks, the congestion resulting from this overhead can result in lost datagrams and retransmissions, as well as excessive propagation time caused by congestion. The Nagle algorithm inhibits the sending of new TCP segments when new outgoing data arrives from the user if any previouslytransmitted data on the connection remains unacknowledged.
精彩评论