[zeromq-dev] AttributeError when using getpeername

Emile Achadde emile.achadde at free.fr
Wed Dec 26 17:44:30 CET 2018


Hello

here is a small script that gives "AttributeError: Socket has no such 
option: GETPEERNAME" why ?

import zmq
import random
import sys
import time

port = "15556"
context = zmq.Context()
socket = context.socket (zmq.PAIR)
socket.bind ("tcp://*:%s" % port)

while True:
     socket.send (b"Server message to client")
     message_b = socket.recv()
     message_s = message_b.decode ("utf-8")
     try:
         (ip_client, port) = socket.getpeername ()
         print ("Connected to '%s:%s'" % (ip_client, port))
     except NameError:
         print ("Erreur pas de client connecté")

     print ("received message from client '%s'" % message_s)
     time.sleep(1)




More information about the zeromq-dev mailing list