Python socket not sending host name

867 views Asked by At

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?

2

There are 2 answers

0
Robᵩ On BEST ANSWER

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.

3
gregb212 On

IS that DETClient the actual implementation? Because it's missing instantiations of both host and port for that instance? in self.connect you're using self.host and self.port, which both evaulate to None since you havent set them yet.

class DETClient(asyncore.dispatcher):

  def __init__(self, host, port):
    self.host = host #<---- this is missing
    self.port = port #<---- this is missing
    asyncore.dispatcher.__init__(self)
    self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
    self.connect((self.host,self.port))