I started with this code from RealPython and began modifying it:
Code: Select all
import socket, utime
host = "10.0.0.191"
port = 15000
from uselect import poll, select
mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mySocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
mySocket.bind((host, port))
mySocket.listen(1)
print('listening on', (host, port))
mySocket.setblocking(False)
myPoll = poll()
myPoll.register(mySocket)
def accept_wrapper(sock):
pass
def service_connection(key, mask):
pass
while True:
events = myPoll.poll(5000)
print(events)
for key, mask in events:
if key.data is None:
accept_wrapper(key.fileobj)
else:
service_connection(key, mask)
utime.sleep(1)
Code: Select all
accept_wrapper
Code: Select all
service_connection
I can't find anywhere details of the string returning from poll.poll().
In microPython docs 1.13 they say it should be a tuple but nothing more specific: https://docs.micropython.org/en/latest/ ... elect.html
The code above treats it as if it were a dict as you can see in the while loop and it returns me an error because...
... when I print it from the above code I get a list:
Code: Select all
[(<socket state=1 timeout=0 incoming=0 off=0>, 1)]
I really can't get out of this after many tries. Please can anyone help me? Thanks!