with the W600 Air602 WiFi i want to build a TCP to Serial communication device.
My problem is that the implementation of
data = connection.recv(16)
is blocking, when a client is connected.
"select","poll" and connection_setblocking(0) samples where not working.
In order to not losse serial data, how to achieve a non-blocking mode?
Code Sample:
Code: Select all
import socket
import sys
def run():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 23)
print('starting up on {} port {}'.format(*server_address))
sock.bind(server_address)
while (True):
print('waiting for a connection')
connection, client_address = sock.accept()
try:
print('connection from', client_address)
while (True):
data = connection.recv(16)
print('received {!r}'.format(data))
if data:
print('sending data back to the client')
connection.sendall(data)
else:
print('no data from', client_address)
break
finally:
# Clean up the connection.
connection.close()
print("closed. ")