LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

A way to disable NAGLE of windows SOCKET

I know that if I use VISA socket, I can change the value of VI_ATTR_TCPIP_NODELAY attribute and enable/disable NAGLE algorithm. How can I do the same thing using standard windows socket? say when I have established my connection by ConnectToTCPServer command.

0 Kudos
Message 1 of 11
(14,284 Views)
you first need to retrieve the system handle for the socket by using GetHostTCPSocketHandle().

then use the setsockopt() function which is part of Windows Socket:

DWORD value = 1;
setsockopt( socket, IPPROTO_TCP, TCP_NODELAY, &value, sizeof( value ) );

but the Windows Socket documentation says it is enabled by default, and i don't think NI specifically disable it... so you may be searching for something else. can you describe further your situation and why you need that option ?
0 Kudos
Message 2 of 11
(14,279 Views)
Thanks for the instruction.
I am sending a file from my PC, to a separate ethernet device, using TCP/IP protocole. I use a user interface, made by CVI for this purpose. When the file is larger than 5K, TCP/IP divides it into  two packets and sends them, and receives a "confirm" message from the device. I know that it is 2 packets because "confirm" is received twice. It takes significantly longer time to send the file in 2 packets than in one. (more than 30 times). When I try to send a slightly smaller file, which fits in one packet, the time is much less.
There were suggestions that it is happening because of NAGLE option of the socket. I also reviewed some posts on this forum and there were suggestions on increasing the size of TCP packet.
Any suggestion on what the reason whould be and how to solve the problem?
Also how to increase the size of TCP packet?

Thanks
0 Kudos
Message 3 of 11
(14,253 Views)
When I include the two line commands that you mentioned in my .c code, it gives me 3 errors:
setsockopt -> Missing prototype
IPPROTO_TCP -> Undeclared identifier
TCP_NODELAY -> Undeclared identifier
0 Kudos
Message 4 of 11
(14,247 Views)
are you aware that :

- it is normal for a tcp stream to divide data into packets ? if your stream is really a tcp stream, and everything is done correctly on the 2 devices (computer and network device) this should be totally transparent. so getting 2 confirmations is an indicator of a limit of the protocol you are using, a broken implementation on the device, or the use of only IP and not TCP.

- IP frames have a finite and somewhat limited length. you can try disabling anything you want, it wont transmit more than 4K of data in one frame. it may be able to do that, but a router in the path may reject the packet and ask for a smaller one.

i do really think that disabling or enabling nagle will not change the behavior you see. i think of a broken implementation of TCP on the device.

to use the function i provided, #include <winsock2.h> and add "ws2_32.lib" to your project. (ha, why does CVI NOT support the #pragma comment( lib, "") syntax)
0 Kudos
Message 5 of 11
(14,240 Views)
Okay, now I am getting really confused... Sorry, it's partly because of my lack of experience... but I'll go ahead and say how I again bumped into a dead end.

I found no winsock2.h under my National Instruments\CVI85\sdk\include  (winsock.h exists though under this folder)      I also found no ws2-32.lib anywhere in under my National Instrument folder. But I found both of them under my MATLAB directory...

So I copy-pasted winsock2.h into National Instruments\CVI85\sdk\include and #include <winsock2.h> in my c application. I also copy-pasted ws2_32.lib into National Instruments\CVI85\extlib, and added it to my project.

When I compile my code this way, it gives me lots of "redefinition of macro " errors, for example for 'WSAEINTR', 'WSAEBADF' and so on...
If I change #include <winsock2.h> to #include <winsock.h>, the compile works fine, but linker gives error "Read error"...

I have no idea what this means and how it can get solved. Thanks again for your time.
0 Kudos
Message 6 of 11
(14,231 Views)
The answer to your previous question:

Yes I am aware that TCP divides data into frames and sends them, waits for ack from the receiver for a certain time, resends it if there is a transmission error and so on.
What I can't understand is why all of a sudden it takes so long to send say 2 frames of data whereas one frame transmission is pretty fast.

In my TCP client application (written by CVI), I am measuring the time from the moment data is transmitted using ClientTCPWrite(), until it receives a reply message from TCP server (running on the separate device) and reads it by ClientTCPRead(). I use Timer() function to measure the mean time. The TCP server should send reply as soon as it receives the data.

When data is sent in one frame, this mean time is somewhere around 5 ms. But as soon as it gets into 2 frames, the time suddenly jumps into 150ms or around...
0 Kudos
Message 7 of 11
(14,230 Views)
there is something wrong with your installation. i have winsock2.h in "National Instruments\CVI85\sdk\include" and ws2_32.lib in "National Instruments\CVI85\sdk\lib\msvc". maybe we didn't check the same options when installing CVI...

(i don't think copying the lib from LabView into CVI is a good idea... but i don't know the details about libraries under LabView)
0 Kudos
Message 8 of 11
(14,226 Views)
ok, it's fine you know how TCP works (it will be simpler...)

it is indeed strange that the reception time jumps so high between 1 and 2 frame transmission. are you sure of the device you are communicating with ? is your network busy or particularly loaded ?

if you are not afraid, you can diagnose the problem further by "sniffing" onto your network. try installing ethereal (with winpcap)(don't forget to reboot after installing), then start capturing on the network card you are using to communicate with your device: go to the "capture/options" menu, and click the "prepare" button for your interface, check "update list of packets in real time", then click "start". now, you will see anything going through your network card. play with your CVI client and your network device, and see how the device is responding to your frames. check for TCP errors and resend. check the times. you may find something strange happening...
0 Kudos
Message 9 of 11
(14,224 Views)
I appreciate all your effort in answering my questions... I did solve the problem with Windows SDK commands. I had not installed it to cvi and when I added Windows SDK to my installation, setsockopt works fine.

I also did disable/enable nagle and it didn't do much in terms of data rate. I have local IPs on both my PC and my ethernet device, and they are directly connected, so there should be no specific network load...  I guess ethereal is the next way to go...
0 Kudos
Message 10 of 11
(14,190 Views)