この関数を使用して、ソケット経由でサーバーを実行します。
def run(self):
# The 'main' function
print 'Running ... '
Running = True
while Running:
InList,OutList,ExceptList = select.select(self.Connections,[],[])
for Connection in InList:
if Connection == self.Server:
# Server got a new connecting Client
User, Adress = self.Server.accept() # New User Connection
Data = {'User':User,'Adress':Adress}
self.Connections.append(Data) # Store the new User Connection
print 'User ', Data, ' connected'
else:
# Some other Socket got data for the Server
Data = Connection.recv(1024)
if not Data:
print 'No new Data!'
break
print Data
ただし、データを送信すると、このエラーが発生します: TypeError: 引数は int である必要があります。または、select() 行である 23 行目に fileno() メソッドが必要です。
マニュアルとそれらの例を調べる ( http://code.activestate.com/recipes/531824-chat-server-client-using-selectselect/およびhttp://ilab.cs.byu.edu/python/select/echoserver .html ) 違いが見られず、なぜ機能しないのか理解できません。self.Connections には Server ソケットのみが含まれており、print self.Connections を使用すると、次のようになります。
[<socket._socketobject object at 0x020B6BC8>]
それは正しいはずのselect()に渡すリストだと述べています。
私は何を間違っていますか?ありがとう!