Reputation:
i use this function to run my Server via Sockets:
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
However when sending data i am getting this Error: TypeError: argument must be an int, or have a fileno() method, on line 23 which is the select() line.
Looking up the manual and those examples (http://code.activestate.com/recipes/531824-chat-server-client-using-selectselect/ and http://ilab.cs.byu.edu/python/select/echoserver.html) i see no difference and dont understand why i wouldn't work. self.Connections contains only the Server socket and when using print self.Connections it gives me:
[<socket._socketobject object at 0x020B6BC8>]
stating, that it's a list i am passing to select() which should be correct.
What am i doing wrong? Thanks!
Upvotes: 0
Views: 223
Reputation: 76194
The first time select.select
runs, there's no problem, because self.Connections
contains only a socket object, which is perfectly valid.
In the second trip through the while
loop, however, self.Connections
has picked up another element: the Data
dictionary constructed in the if Connection == self.Server:
block. That dictionary is not an integer, and it doesn't have a fileno
method, so select.select
complains when it sees it.
Upvotes: 1