By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

socket.connect | gaierror: [Errno 11004] getaddrinfo failed

P: 9
Hi all,
I am having trouble getting a client/server relationship to connect; receiving the above error.
Python 2.6.5, Win7

On one end we have the socket being bound and that is all working with correct (IP) and as far as I know, correct socket settings.
Expand|Select|Wrap|Line Numbers
  1. def listen_for_peer_setup(server_connection):
  2.     listening_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  3.     listening_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
  4.     local_bind_ip = server_connection.getsockname()
  5.     listening_socket.bind((local_bind_ip[0], 9010))
  6.     Thread(target=listen_for_peer(listening_socket)).start()
  7.  
  8. def listen_for_peer(listening_socket):
  9.     TIMEOUT = 5 #Max thread kill time
  10.     listening_socket.listen(1) #Only taking 1 client
  11.  
  12.     if client_flags.stop_threads == True:
  13.         pass
  14.  
  15.     read_socket =[listening_socket] #Only setting the/a variable here incase more develop later
  16.  
  17.     while True:
  18.         read_results = select(read_socket, [], [], TIMEOUT)
  19.         if client_flags.stop_threads == True:
  20.             break
  21.  
  22.         elif listening_socket in read_results[0]: #Peer has contacted us
  23.             new_con, new_addr = self.connections.accept()
  24.             print "Server has connection"
  25.             client_flags.ready = False
  26.             global peer_con
  27.             peer_con = new_con
  28.             Thread(target=data_stream_read).start()
  29.  
On the other end is the client
Expand|Select|Wrap|Line Numbers
  1. def connect_peer(address):
  2.     peer_con_l = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  3.     while True:
  4.         if client_flags.stop_threads == True:
  5.             break
  6.         else:
  7.             peer_con_l.connect((address[0], 9010)) #<Fails at this line
  8.             print "Peer has connection"
  9.             global peer_con
  10.             peer_con = peer_con_l
  11.             break
  12.  
Obviously there is some threading going on but I doubt that is causing my error.
I took a look through the socket module's code and couldn't even find the reference to getaddrinfo that the error mentions.

I've made other server/client style connections in a similar manner as this before (I'm copying a lot of logic) which might be why I can't find the problem but as far as I know this should work.

I've googled all around and failed to find anything helpful.

Please advise,
Cheers
Jul 14 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.