Hi,
I have a function that creates a socket for UDP connection and it works fine.
Code: Select all
def connect():
conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# server_address = (ip, port)
print ('starting up on %s port %s' % server_address)
conn.bind(server_address)
conn.settimeout(0)
# conn.settimeout(None)
return(conn)
But when the program start, right after connect() function, another function which receives from the socked is called. I noticed that if there is not enough time period between the two calls, connect() function returns None and the program crashes. I put some delays between the two calls, but I want to have more robust code. As far as I know, there is no method like isConnected() in usocket library. How can I hold the program execution until the socket binding is ready?
When I check what Connect() function returns I see something like this:
Code: Select all
<socket state=0 timeout=0 incoming=3fff99d0 off=0>
When there is not a successful connection it returns "incoming=None". Is there way of manipulating this returned statement? (I do not know what type of data is this).
Thanks.