执行这个socket客户端。出错:error: [Errno 10053]
1。
#应用实例的服务器端
import socket;
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM); #生成Socket对像
sock.bind(('localhost', 8001)); #绑定主机IP与端口号
sock.listen(5); #开始监听
while True:
connection, address = sock.accept(); #
try:
connection.settimeout(5); #在5秒后调用这个函数
buf = connection.recv(1024);
if buf == '1':
connection.send('lkafds');
else:
connection.send('false');
except socket.timeout:
print 'time out';
connection.close();
sock.close();
#socket 小实例 客户端代码
import socket
import time
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM); #
sock.connect(('localhost', 8001)); #
time.sleep(2);
sock.send('1');
print sock.recv(1024);
sock.close();
Traceback (most recent call last):
File "F:/python/pyweb/1.1.7.py", line 8, in <module>
print sock.recv(1024);
error: [Errno 10053]