python sockets stop recv from hanging?
pygame, python, sockets
Solution
Use nonblocking mode. (See `socket.setblocking`.)
Or check if there is data available before call `recv`. For example, using `select.select`:
r, _, _ = select.select([self.conn], [], [])
if r:
# ready to receive
message = self.conn.recv(1024)
Problem
I am trying to create a two player game in pygame using sockets, the thing is, when I try to receive data on on this line: ``` message = self.conn.recv(1024) ``` python hangs until it gets some data. The problem with this is that is pauses the game loop when the client is not sending anything through the socket and causes a black screen. How can I stop recv from doing this? Thanks in advance