LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

setsockopts() / SO_KEEPALIVE support for servers?


@AllenHuffman wrote:

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?


Well I suppose you could always link to that function yourself. It's not something you want to do for a large amount of functions but for one single function should be no problem.

 

typedef int (WSAAPI *WSAIoctlPtr)(
  SOCKET                             s,
  DWORD                              dwIoControlCode,
  LPVOID                             lpvInBuffer,
  DWORD                              cbInBuffer,
  LPVOID                             lpvOutBuffer,
  DWORD                              cbOutBuffer,
  LPDWORD                            lpcbBytesReturned,
  LPWSAOVERLAPPED                    lpOverlapped,
  LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);

int WSAAPI WSAIoctlFunc(
  SOCKET                             s,
  DWORD                              dwIoControlCode,
  LPVOID                             lpvInBuffer,
  DWORD                              cbInBuffer,
  LPVOID                             lpvOutBuffer,
  DWORD                              cbOutBuffer,
  LPDWORD                            lpcbBytesReturned,
  LPWSAOVERLAPPED                    lpOverlapped,
  LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
{
    HMODULE handle = LoadLibrary("ws2_32.dll");
    if (handle)
    {
        WSAIoctlPtr func = (WSAIoctlPtr)GetProcAddress(handle, "WSAIoctl");
FreeLibrary(handle); if (func)
return func(s, dwIoControlCode, lpvInBuffer, cbInBuffer, lpvOutBuffer, cbOutBuffer, lpcbBytesReturned, lpOverlapped, lpCompletionRoutine);
}
return WSASYSNOTREADY; }

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 11 of 14
(1,059 Views)
@rolfk wrote:

Well I suppose you could always link to that function yourself. It's not something you want to do for a large amount of functions but for one single function should be no problem.

Thanks for that -- good trick to know.

 

0 Kudos
Message 12 of 14
(1,054 Views)

I am unable to work on this project at the moment, but it looks like using a timer and "DisconnectTCPClient()" might also do the trick, assuming the server is then available and ready for another connection.

 

The issue is if a remote client goes away (cable pull, power off, etc.) and no TCP_DISCONNECT is seen, the code sits there "forever" (?). It shouldn't do that, so plan to fix that.

0 Kudos
Message 13 of 14
(997 Views)

Since my goal was to disconnect a listening server (in case something happened to the remote Client and no Disconnect was sent), I ended up using a Timer. In the handler, I'd increment a counter, which I reset on any new connection (we only allow one at a time) or any time TCP data comes in. If that counter hits a threshold (X seconds), I used the Client TCP Disconnect call to force close. Then the server will recycle. This works fine for what I needed to do.

0 Kudos
Message 14 of 14
(932 Views)