python中的非阻塞套接字编程

python中的非阻塞套接字编程,python,sockets,nonblocking,Python,Sockets,Nonblocking,我正在尝试编写一个非阻塞套接字代码。到目前为止,我已经尝试过: server.py import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setblocking(0) s.bind(('localhost',60003)) s.listen(1) #print 'Connected by', addr while 1: conn, addr = s.accept() conn.setbl

我正在尝试编写一个非阻塞套接字代码。到目前为止,我已经尝试过:

server.py

import socket   

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setblocking(0)
s.bind(('localhost',60003))
s.listen(1)
#print 'Connected by', addr
while 1:
    conn, addr = s.accept()
    conn.setblocking(0)
    data = conn.recv(1024)
    conn.sendall(data)
print 'the normal execution of data should continue'
print 'but when client connects, it has to echo back to the client then again continue its execution'
client.py

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost',60003))
s.sendall('Hello, world')
data = s.recv(1024)
#s.close()
print 'Received', repr(data)
我还收到以下错误:
socket.error:[Errno 11]资源暂时不可用

无论我更改端口号多少次


谢谢

您已将服务器设置为非阻塞状态,因此
accept
会立即返回并出错。将服务器设置为阻塞或使用
选择
等待多个套接字上的事件。

应该是
s.setblocking(0)
哦,对不起,这是一个输入错误