Hi there!
I’m trying to learn Micropython from your book: MicroPython_Programming_with_ESP32_and_ESP8266_V1_2. I’d like some questions cleared if possible:
. page 159, line “conn, addr = s.accept() “
I believe you are creating two variables: conn and addr, the first being a new socket for connecting to the client, however I don’t understand how it is populated. The addr variable I believe to be the ip address of the client returned by s.accept()
.page160, line: “ print(‘Got a connection from %s’ % str(addr))
I get the client ip address printed in the terminal followed by a , and another number
the %s is a string defined by %str(addr) portion? right?
what is the other number printed on the terminal after the ip address?
Thanks in advance, sorry for my “noobness”
Hi.
That method returns two variables. Here’s the description from the documentation:
socket.accept()
“Accept a connection. The socket must be bound to an address and listening for connections. The return value is a pair (conn, address) where conn is a new socket object usable to send and receive data on the connection, and address is the address bound to the socket on the other end of the connection.” https://docs.micropython.org/en/latest/library/usocket.html#usocket.socket.accept
As for the other question. I’m not really sure what the number that follows the IP address means. Is it different for each connection, right? I think it is a unique number used to identify the connection.
I’m sorry that I can’t help much.
Regards,
Sara
You have been most helpful. Thanks a lot.
By the way the %s is a string defined by %str(addr) portion? Or is it related to the socket variable s?