Friday, 23 August 2013

maintain multiple socket connections while putting the recv through a single handler in python

maintain multiple socket connections while putting the recv through a
single handler in python

i have a function that returns a host for a specific site. and using these
two functions
def connect(self, rooms):
print('')
i = [x for x in rooms]
for x in i:
self.room_connect(x)
running = True
while running:
self.event_data()`
def room_connect(self, rooms):
host = getServer(rooms)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, 443))
sock.send(self.room_auth(rooms).encode())
self.sockets = sock
print(self.sockets)
print('connected to '+ rooms)
self.postbyte = True
i am able to connect to a different socket for each host. the problem is,
i need it to maintain a connection with each socket it connects to. in the
end, only the last socket that is created in the for loop is maintained.
the socket recv data from that socket is passed in to a handler to parse
the info. basically what i am asking is how to keep a connection from each
of the sockets created in the for loop going while passing its recv info
in to the handler. the handler is the event_data() and in the event_data
function the data to parse is defined by data = self.sockets.recv(1024).
the problem is that the only the last socket from the for loop is left
over to be handled.

No comments:

Post a Comment