I need some help. I'm working on a legacy software that uses python 2.5.4 running on Windows7 and I need to enable keepalives in my socket connection.
I've seen in the thread below that you can enable keepalives in python using
object.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
However this setup uses the default windows keep alive timer of 2 hours.
I've also seen that we can set the timer using the following API, however it is only available for Python 2.6 onwards.
sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 10000, 3000))
Is there anyway I can set this SIO_KEEPALIVE_VALS using python 2.5.4 ? The legacy code I have also has the module pywin32-214. I really can't upgrade the python version.
I also wonder how python2.6 and newer calls the windows api
int WSAIoctl(
(socket) s, // descriptor identifying a socket
SIO_KEEPALIVE_VALS, // dwIoControlCode
(LPVOID) lpvInBuffer, // pointer to tcp_keepalive struct
(DWORD) cbInBuffer, // length of input buffer
NULL, // output buffer
0, // size of output buffer
(LPDWORD) lpcbBytesReturned, // number of bytes returned
(LPWSAOVERLAPPED) lpOverlapped, // OVERLAPPED structure
(LPWSAOVERLAPPED_COMPLETION_ROUTINE) lpCompletionRoutine, // completion routine
);
Thanks for your help.
References: How to change tcp keepalive timer using python script?
https://msdn.microsoft.com/en-us/library/dd877220%28v=vs.85%29.aspx