0

I am trying to connect my client to another client through a server, however while I'm waiting to start up the other client, this socket is closed due to the recv() call do you guys have any ideas on how I can keep the socket open while waiting on the connection from the other side? After the first res call an empty string is returned everytime.

    client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    client.connect((server_ip,server_port))
    client.settimeout(CONNECTION_TIMEOUT)
    while True:
        try:
            toSend = #the hello message that contains the connection id
            client.send(toSend.encode())
            # print("Sent")
            res= client.recv(1024)
            print(res.decode())
            if 'OK' in res.decode():
                break
        except client.timeout as e:
            continue
Jokester2
  • 1
  • 3
  • you'll find detail explanations on socket time in these to SO post, https://stackoverflow.com/questions/2719017/how-to-set-timeout-on-pythons-socket-recv-method and https://stackoverflow.com/questions/16745409/what-does-pythons-socket-recv-return-for-non-blocking-sockets-if-no-data-is-r (hope this helps) – mzm Dec 04 '22 at 03:05

0 Answers0