'Python socket.recv() is waiting and don't read data while data is flowing
I'm using python for reading barcode code numbers. At first everything is ok. But after a while (I don't know the exact time) socket.recv doesn't get the data from barcode reader. When I restart the program everything works fine again. I put counter for reset socket connection and also put timer again for reset connection but it didn't work. I've been trying to solve this for weeks. Does anybody know this problem. You can find my recv codes below :
def getBarcodeValue(client_socket):
print("Waiting to reading...")
data = ""
r, _, _ = select.select([client_socket], [], [])
if r:
try:
# ready to receive
data = client_socket.recv(1024) # most 1024 bytes can be read.
data = data.decode("utf-8")
return data
# print("Data :", realData)
# print("Byte size", len(realData))
# print("Data type :", type(realData))
except socket.timeout as e:
err = e.args[0]
if err == errno.EAGAIN or err == errno.EWOULDBLOCK:
sleep(1)
print('No data available')
else:
# a "real" error occurred
print(e)
# sys.exit(1)
print("Data receive error")
except socket.error as e:
# Something else happened, handle error, exit, etc.
print(e)
print("socket.error")
After a while program prints "waiting to reading" and it waits until forever.
Edit1 : Program doesn't throw any error. It just waits until forever after printed the "waiting to reading" string. At first everything is ok. While products is flowing conveyor also barcode reader is reading barcodes and give output.However, socket.recv() doesn't get data after a while.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
