python socket 问题...
# Echo client program
import socket
HOST = 'localhost.' # The remote host
PORT = 32001 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', repr(data)
# Echo server program
import socket
HOST = '' # Symbolic name meaning all available interfaces
PORT = 32001 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()
为什么老返回:
s.connect((HOST, PORT))
File "<string>", line 1, in connect
error: [Errno 10061]
我换其他的地址名也一样这回事的呢?大家运行一下,看看有没有我这种情况;(防火墙我关了)
[解决办法]
没有错啊
E:\spider_shh\test>python client.py
Received 'Hello, world'
E:\spider_shh\test>python server.py
Connected by ('127.0.0.1', 4179)
E:\spider_shh\test>
[解决办法]
server脚本先跑,再执行client