How to get client address as a server using sockets
Posted: Thu May 06, 2021 4:01 pm
A small background:
I'm developing a minimal resource server that is meant to respond to simple pings and send some JSON messages and so on. I want to be able to track the IP address of every client that has pinged the server, but I can't find any solution to this on the internet except for one person asking the exact question with no answer.
To connect to a client I approximately do this:
In normal python, then addr would have ended up as a list where you easily could retrieve an IP address, and port. But micropython returns a bytearray, which I don't know how to interpret (socket.inet_ntop(socket.AF_INET, addr) does not work properly). Is there any way to do this, or just somewhere that can describe how this bytearray format works?
Github repo: https://github.com/the-lockedcraft-lega ... ntomServer
I'm developing a minimal resource server that is meant to respond to simple pings and send some JSON messages and so on. I want to be able to track the IP address of every client that has pinged the server, but I can't find any solution to this on the internet except for one person asking the exact question with no answer.
To connect to a client I approximately do this:
Code: Select all
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSocket.bind(addr_info[0][-1])
serverSocket.listen(1)
(conn, addr) = self.serverSocket.accept()
Github repo: https://github.com/the-lockedcraft-lega ... ntomServer