socket server - getting a connected user's ip

DeanMWake picture DeanMWake · Sep 6, 2013 · Viewed 13.4k times · Source

I have just started to make a simple socket "chat" server where users connect to my server through telnet. I was wondering how I could get the connected users IP address so that It would print out that users message like so:

IP address: "Hello"

This is the code I am using so far:

def broadcast(self, message):
      for sessions in self.sessions:
          sessions.push('>>' + message + '\r\n')

Thanks in advance, If you need any more information please ask.

EDIT:

A link to the entire program: http://pastebin.com/9vzuiLZe

Answer

staticd picture staticd · Sep 6, 2013

<your-socket-instance>.getpeername() will give you what you want