0

这里的代码片段:

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]

4

1 回答 1

4

Just replace this line:

s.bind(('127..0.0.1',PORT))

with this:

s.bind(('127.0.0.1',PORT))
于 2013-05-08T13:20:11.753 回答