I am using VB 6 with Winsock Control to build a TCP/IP based client. The server is NOT written by me and I don't have access to its source code, therefore I can't change the server in any way.
The client connects to the server through TCP/IP and then sends some commands for the server. The problem is that the server is built with the assumption that each TCP/IP packet would contain only ONE command therefore no delimiter is used for separating commands. Now when my client application sends multiple commands by calling SendData() method of Winsock control for each command, the Winsock combines those small packets with commands into a larger packet and then sends it. Winsock uses "Nagle algorithm for send coalescing", as mentioned in MSDN.
When this packet with multiple commands is received by the server, it is not accepted by it because now it has more than one command in a packet therefore it's not according to its format.
Therefore, what I need, is a way to “flush” the data before calling the SendData() method again so that new command is not concatenated with the previous ones.
From MSDN I came to know about a Winsock option "TCP_NODELAY", which does this, but it does not seem to work for me. Although I set this option but the behavior of the Winsock remained the same (I used sniffer to examine the packets). I also came to know that SDK for Win CE contained a bug which caused Winsock to ignore this option value. But I didn't find any article which indicated that this bug also exists in Win 9x/2000/XP.
I think an example would clear what I want to do.
I want to send some text/commands on TCP connection. They should be send in a way such that each packet contain only one command:
Packet 1 --> Command_1
Packet 2 --> Command_2
Packet 3 --> Command_3
But when I send the data using SendData() method of Winsock control:
Winsock combines all three commands in a single packet as :
Packet 1 --> Command_1Command_2Command_3
While I want winsock to send each command in a different TCP packet. That is, I want to packetize the TCP stream. I tried to enter some delay between SendData() calls but many times it also results in the concatenation of the commands. Besides this, I read in one article that the routers or destination end-point may combine the packets.
I would highly appreciate if you can help me.