Skip to content Skip to sidebar Skip to footer

How To Set Keep-alive Timer In Python 2.5 Running In Windows 7

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

Solution 1:

Here is how you do it in c

static PyObject*
sock_ioctl(PyObject *argO , PyObject *arg)
{
PyObject *s;
DWORD recv;
struct tcp_keepalive ka;
if (!PyArg_ParseTuple(arg, "O(kkk):keepalive",&s,
    &ka.onoff, &ka.keepalivetime, &ka.keepaliveinterval))
    return NULL;

if (WSAIoctl(PyObject_AsFileDescriptor(s), SIO_KEEPALIVE_VALS, &ka,  sizeof(ka),
    NULL, 0, &recv, NULL, NULL) == SOCKET_ERROR) {
    return set_error();
}
return PyLong_FromUnsignedLong(recv);
}

I made a small python extension in github https://github.com/rawinput/ioctl compiled for python 2.5


Post a Comment for "How To Set Keep-alive Timer In Python 2.5 Running In Windows 7"