below is mycode though i have set keepalive, socket connection gets closed after sometime.

        sb_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,socket.SOL_TCP)
        sb_sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
        sb_sock.connect((msg_host, host_port))
        reg_msg="REG 0000 "+finder_id+"\r"
        sb_sock.send(reg_msg)

i was able to acive this with below lines of code

        sb_sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 30000, 30000))
commented: Thank you for sharing! +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.