这里是代码段:
import socket,sys
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
MAX = 65535
PORT = 6000
if sys.argv[1:]==['server']:
s.bind(('127..0.0.1',PORT))
print 'Listnening at ',s.getsockname()
while True:
data ,address = s.recvfrom(MAX)
s.sendto('Your data was %d bytes' %len(data),address)
elif sys.argv[1:] == ['client']:
print 'Address before sending'.s.getsockname()
s.sendto('This is my message ',('127.0.0.1',PORT))
print 'Address after sending ',s.getsockname()
data,address = s.recvfrom(MAX)
print 'The Server ',address,' says',repr(data)
else:
print >>sys.stderr, 'Usage: udp_local.py server|client'
我收到错误[socket.gaierror:[Errno 11004] getaddrinfo failed]
答案 0 :(得分:4)
只需替换此行:
s.bind(('127..0.0.1',PORT))
用这个:
s.bind(('127.0.0.1',PORT))