08-26-2019 10:42 AM
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?
08-26-2019 11:08 AM
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.
08-27-2019 08:13 AM
Microsoft seems to believe that this option is supported by the Winsock implementation.
https://docs.microsoft.com/en-us/windows/win32/winsock/so-keepalive
08-27-2019 09:06 AM
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.
08-28-2019 03:18 AM - edited 08-28-2019 03:25 AM
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.
09-04-2019 10:47 AM - edited 09-04-2019 10:48 AM
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?
09-04-2019 12:04 PM
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.
09-04-2019 03:15 PM
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?
09-05-2019
02:18 AM
- last edited on
11-18-2024
04:39 PM
by
Content Cleaner
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?
09-05-2019
09:03 AM
- last edited on
11-18-2024
04:37 PM
by
Content Cleaner
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.