Python Forum

Full Version: List referencing.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there.

I've borrowed a little code from a site I've long since lost, sorry, I wanted to say thanks to the OP.

However, I'm using the following:
clients=[clientsocket]

clientsocket, clientaddr = serversocket.accept()
clients.append(clientsocket)
thread.start_new_thread(handler, (clientsocket, clientaddr))

Which is great, it opens connections, multiple at the same time, and data comes in really well. But I'd like to create a log of the data received, and from which host. The host is open to my subnet so there could be multiple machines.

So in the routine where the data is received data = clientsocket.recv(1024)
how/where do I get the client socket host, or unique identifier?

The reason being, although this is not strictly necessary at the moment, because the code runs on threads it's very possible the update routines kicked off by the data can be running simultaneously. This makes any printed log file a bit of a mess! So I'd like to have at the very least an identifier at the start of each log line.

Many thanks.