Question is: How can I send two strings using SendData in different packets?

Because when I try to send two strings one after another, winsock joins them in a single packet thus making one string received from client/server. For example:

Winsock1.SendData "String1"
Winsock1.SendData "String2"

The final received data will be: "String1String2"
I guess winsock joins data that are sent in short period of time, is there any way to avoid this?

If the packets are analyzed by any sniffer software, there will be one packet containing both strings. Is there any way I can send these two strings separately, in different packets of TCP?

Direct solution encouraged, less workarounds.
Thank you in advance.

6 Years
Discussion Span
Last Post by whitejava

Personally, I haven't ever run across a requirement to separate successive calls into discrete packets. However, other experience with the WinSock control leads me to offer this suggestion: after each SendData invocation, put in a "DoEvents" command like so:

Winsock1.SendData "String1"
Winsock1.SendData "String2"

In other instances of using WinSock methods, I've used this technique to give the outer (invisible to VB) message loop time to finish processing all the socket messages enough to complete discrete messages. You may have to do something similar on the Accept side (in between GetData calls) but that's just a guess.

I don't know if this will work (I haven't tested it) but it's a small change, and it's something to try as a science experiment. If it works, great, and we've all learned something. If not, I don't really have another suggestion (sorry).

Good luck!

Edited by BitBlt: n/a


Unfortunately it didn't work. I'm grateful for you reply and suggestion.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.