2016-04-13 40 views
-1

Bloke edici olmayan bir soket kodu yazmaya çalışıyorum.Python'da engellenmeyen soket programlama

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

Ayrıca
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) 

alıyorum bu hata

server.py: Şimdiye kadar bu denedim socket.error: [Errno 11] Resource temporarily unavailable

olursa olsun ne olursa olsun ya da bununla birlikte pek çok kez port numarasını değiştiririm.

Teşekkürler!

+0

's.setblocking (0)' – stark

+0

oh özür dileriz, bu bir yazım hatası oldu – Anusha

cevap

1

Sunucunuzu engellemeye ayarladınız, bu nedenle accept hemen bir hatayla geri dönüyor. Ya sunucuyu engelleyecek şekilde ayarlayın veya birden çok yuvadaki olayları beklemek için select kullanın.