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.
#WJ

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"
DoEvents
Winsock1.SendData "String2"
DoEvents

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!

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.