LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

setsockopts() / SO_KEEPALIVE support for servers?

A quick search through this forum and the help file didn't show me anything obvious... Is there LabWindows networking support to alter the keepalive (such as standard TCP/IP setsockopts call and SO_KEEPALIVE)? I see posts here pointing folks to doing it using standard Winsock, but since this is such a standard part of TCP/IP networking I figure there is probably a built-in way?

0 Kudos
Message 1 of 14
(4,306 Views)

I do see that...

 

GetHostTCPSocketHandle ();

...exists, which I hope would enable use of standard WinSock calls such as setsockopt():

 

https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt

Perhaps that's just the way it works here.

Now it seems that Windows may not allow setting the actual Keep Alive time, as I keep finding references to editing a global setting in the registry:

 

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

Thanks for any tips. It looks like I can at least edit a registry setting and use setsockopt() to enable.

 

0 Kudos
Message 2 of 14
(4,296 Views)

Microsoft seems to believe that this option is supported by the Winsock implementation.

 

https://docs.microsoft.com/en-us/windows/win32/winsock/so-keepalive

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 14
(4,248 Views)

I agree. If there is no way to do this using the LabWindows API, I hope that access to winsock is available. The goal is to prevent a server application from hanging "forever" if the remote client is disconnected (cable pull) and never sends a Disconnect.

0 Kudos
Message 4 of 14
(4,240 Views)

I haven't tried it but the function

GetHostTCPSocketHandle ();

that you found seems to be exactly what you want to use for this. It exists to allow exactly this kind of functionality since the LabWindows/CVI developers can't possibly expose every single option to the API level (it also varies depending on OS and even the version of the OS).

 

PS: Be prepared to maintain your application in the future. Microsoft has been changing the functionality of some of the WinSock options regularly in the past and is likely going to do that in the future too. Some of the technology in the socket library is from days where hackers were dialing in over modems into systems, not where they had free access to every possible device over the vast internet, and as such can turn out to be more of a liability nowadays than a feature. So features do get tweaked and that applies to socket options in particular.

Rolf Kalbermatter
My Blog
Message 5 of 14
(4,222 Views)
int GetHostTCPSocketHandle (unsigned int conversationHandle, intptr_t *socketHandle);

From the docs, "conversationHandle" is returned from a Client connection. I do not see how to obtain it from the server side. Maybe I can't do this.

 

But indeed, SO_KEEPALIVE can be turned on, and SIO_KEEPALIVE_VALS can be used to set the timeout on a per-connection basis.

 

Anyone know what this conversationHandle is for a server connection?

0 Kudos
Message 6 of 14
(4,167 Views)

Posting my research...

 

My goal is to take an existing LabWindows server app and update it so it won't sit there forever if a cable disconnects or a remote client crashes/reboots without sending a DISCONNECT. By enabling KEEP ALIVE, I expect I can get an automatic disconnect if the client isn't seen after awhile. If this isn't easy, we'll just do our own timeout and close/restart the connection if we don't hear anything from the remote client after awhile.

 

SIO_KEEPALIVE_VALS can handle both enabling KEEP ALIVE and setting the timeout values:

 

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/dd877220(v=vs.85)

 

It uses WSAIoctl()/WSPIoctl(), which are new calls to me. I am trying to get an example linked in with some LabWindows code and after including the various header files, I end up with...

 

error: Undefined symbol '_WSAIoctl@36'

I'm new to Windows programming and LabWindows, but it looks like I need to find out how/where to include the Win library.

 

That said, this call also wants a socket, which I am still researching how to get from a client app. I've seen various posts here going back over a decade with others asking about WIN32 API calls, so I'll continue my search.

 

0 Kudos
Message 7 of 14
(4,159 Views)

After adding the .lib to the project, I now get an error that using this library is only available in the "Full Development System." Indeed, my install says Base.

 

Am I completely out-of-luck at using WIN32 APIs with my version?

0 Kudos
Message 8 of 14
(4,144 Views)

On this page in the last section it explicitly states that you can also use GetHostTCPSocketHandle() on a server handle. You would probably want to call that in the TCP_CONNECT case inside your TCPServerCallback() function and use the handle parameter as conversationHandle.

 

I don't know about your other problem but I guess it makes sense that the base package wouldn't support certain things and this could be one of them. But how did you run your previous tests with setsockopt() then?

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 14
(4,119 Views)

On Availability of Windows SDK Functions help page you'll see a list of functions included in the Windows SDK and their availability in base and full CVI package.

Beware: it will take *long* time to load, but the same content is available on CVI help as well.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 10 of 14
(4,105 Views)