Python,socket.error:[Errno 10049]

时间:2013-10-25 20:54:23

标签: python sockets

在简单聊天客户端的基础上工作,并收到以下错误:
socket.error: [Errno 10049] The requested address is not valid in its context

代码是:

from socket import *
HOST = ''
PORT = 8000
s = socket(AF_INET, SOCK_STREAM)
s.connect((HOST, PORT))
i = True
while i is True:
    msg = raw_input("Write A MSG: ")
    s.send(msg)
    print "Awaiting reply"
    reply = s.recv(1024)
    print "Recived: ", repr(reply)

s.close()

感谢您的帮助。

2 个答案:

答案 0 :(得分:4)

错误是:

...
s.connect((HOST, PORT))

这是因为HOST = ""。您可以在 绑定 套接字时使用HOST = ""。但是在连接时,您应该使用HOST = "localhost"HOST = "someaddr.com"

答案 1 :(得分:2)

IP地址(HOST)不正确。如果您想从本地计算机访问它,可以使用'127.0.0.1''localhost'。要从任何地方访问,请使用'0.0.0.0'