|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Multiple Socket Connections - How-to?
Ok, heres the deal. I have a flatfile with a list of proxy address' and ports, they take the form of server
ortNow, what I havew is some code to readlines() the text file and split it into two values to be used. Now, For every entry in this list, I want to open a socket connection to the proxy server to see if it's alive. This is how far I have gotten with my code. What seems to be happening is sockets are being opened, but blocked. I've looked everywhere on decent docs to help me through this, but I've no luck. I'm guessing I need to use select() to move through each connection. I want to be able to simultaneously, or close to simultaneously, open up several connections on seperate sockets. I thought that creating a new socket for each loop through, would allow me to do this, but nope, it doesn't. I even tried taking the server/port values, sticking them in a list, then looping through each of them. Anyone who could help me out at all would be a savior. Yours, Estron print "Preparing to connect..." for self.entry in self.proxylist: # set string seperator self.dlm = re.compile(r':') #split string by seperator self.lst = self.dlm.split(self.entry) # create new proxy object self.po = proxy_object() # set up proxy_object socket self.po.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # set proxy_object to non-blocking socket self.po.conn.setblocking(0) # set proxy_object name self.po.name = self.lst[0] # set proxy_object server self.po.serv = self.lst[0] # set proxy_object port self.po.port = int(self.lst[1]) # append proxy_object to proxygroup list self.proxyobject = self.po proxygroup.append(self.proxyobject) # Begin connecting to all box' in the proxygroup for box in proxygroup: print self.po.conn, "connecting to", self.po.name, "on port", self.po.port rr, rw, ie = select.select([box.conn], [box.conn], [box.conn], 3) try: box.conn.connect(("www.google.com", 80)) except socket.error, msg: print "Error", msg print rr, rw, ie |
|
#2
|
||||
|
||||
|
__________________
Lucas Marshall |
|
#3
|
|||
|
|||
|
Aye, I've tried asyncore.
That works to an extent; handling connections, sending requests etc. but it seems to pipeline them. E.g. If I place the asyncore.loop() inside a for loop, for each socket connection thats made, it makes, the asyncore.loop handles the select routine (I guess), but blocks the next connection to be made in the loop until the previous one is complete. If I move the asyncore.loop() outside of the for loop, all the connections are made first and foremost, then the asyncore.loop() is called and checks for writeable sockets, if writeable, the request is sent off. Now, while that request is sent off, if the proxy is latent, then the next request isn't sent off. Mind you, I could be wrong and it's just looping through all the socket connection to see which are ready to send requests and receive them. Would that be the case? I think thats the meat of my question: when using asyncore.loop(), does it loop through all socket connections and check for r, w and except, then handle it? E.g. If a socket is ready to write to, it will send whatever request via the socket then move on in the loop looking for the next socket thats ready to be used. If it does that, then does it block while sending (assuming the server is latent)? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Multiple Socket Connections - How-to? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|