socket.getsockname

socket.getsockname()

  • This function returns the address of the client socket
  • Typically, this refers to the client address
  • The return value is usually a tuple (ip_address, port)
  • The client socket must be connected already

Example of getsockname

>>> import socket
>>> sock = socket(AF_INET, SOCK_STREAM)  # client socket
>>> client_addr = ('localhost', 25000)
>>> sock.connect(client_addr)
>>> sock.getsockname()
('127.0.0.1', 25000)

References

Previous
Next

socket.gethostname

socket.getpeername