Search code examples
pythonsocketsasyncore

Python socket not sending host name


I am using an asyncore.dispatcher client on python to connect to a server developed in LabWindows running on a PC. Here's the code snippet on the client that connects to the server:

class DETClient(asyncore.dispatcher):

   def __init__(self, host, port):
      asyncore.dispatcher.__init__(self)
      self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
      self.connect((host,port))

On the server side, my Labwindows code is looking for two parameters, TCPPeerName and TCPPeerAddr:

GetTCPPeerName (handle, peerName, sizeof (peerName));
GetTCPPeerAddr (handle, peerAddress, sizeof (peerAddress));

It seems that the python code is not passing the hostname at all, because my server gets a NULL for PeerName.

Do I have to do anything to specifically make the asyncore client to send the PeerName when establishing a connection?


Solution

  • Do I have to do anything to specifically make the asyncore client to send the PeerName when establishing a connection?

    No, you don't, because TCP clients don't send names when establishing a connection. They send addresses.

    GetTCPPeerName is almost certainly calling gethostbyaddr(X), where X is the address returned by GetTCPPeerAddr. In your case gethostbyaddr() is failing because the information is not available.

    This means that your hostname resolution database is missing some data -- you might need to update your DNS, your hosts file, your WINS data, or wherever your host name data lives.