SunQuest
           Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 28th, 2002, 11:15 AM
estron estron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 40 estron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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 serverort

Now, 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

Reply With Quote
  #2  
Old November 7th, 2002, 12:04 PM
ZeUs's Avatar
ZeUs ZeUs is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: St. George, Utah
Posts: 63 ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 31
__________________
Lucas Marshall

Reply With Quote
  #3  
Old November 7th, 2002, 11:36 PM
estron estron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 40 estron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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)?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Multiple Socket Connections - How-to?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway