09-05-2019 03:43 PM - edited 09-05-2019 03:52 PM
@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; }
09-05-2019 03:47 PM
@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.
09-17-2019 09:28 AM
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.
09-25-2019 01:43 PM
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.