Python error: “socket.error: [Errno 11] Resource temporarily unavailable” when sending image

前端 未结 1 921
情歌与酒
情歌与酒 2021-01-04 06:44

I want to make a program that accesses images from files, encodes them, and sends them to an server. Than the server is supposed to decode the image, and save it to file. I

相关标签:
1条回答
  • 2021-01-04 07:22

    In the server you are setting the remote socket (that returned by accept()) to non-blocking mode, which means that I/O on that socket will terminate immediately by an exception if there is no data to read.

    There will usually be a period of time between establishing the connection with the server and the image data being sent by the client. The server attempts to immediately read data from the client once the connection is accepted, however, there might not be any data to read yet, so c.recv() raises a socket.error: [Errno 11] Resource temporarily unavailable exception. Errno 11 corresponds to EWOULDBLOCK, so recv() aborted because there was no data ready to read.

    Your code does not seem to require non-blocking sockets because there is an accept() at the top of the while loop, and so only one connection can be handled at a time. You can just remove the call to c.setblocking(0) and this problem should go away.

    0 讨论(0)
提交回复
热议问题