Я после этой example,Как решить ошибку сокета python?
#!/usr/bin/python # This is server.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
c.send('Thank you for connecting')
c.close() # Close the connection
, и я получаю эту ошибку, несмотря на хорошую сеть:
>>> s.bind((host, port))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/anaconda/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Как я могу это исправить?
Какова ценность 'host'? Возможно ли, что 'socket.gethostname()' возвращает недопустимое имя хоста? –
http://stackoverflow.com/questions/15246088/what-does-this-socket-gaierror-mean –
Что произойдет, если вы попробуете: 's = socket.socket (socket.AF_INET, socket.SOCK_STREAM)'? И если это не работает, попробуйте изменить 'host = '''? – shuttle87