469,945 Members | 2,312 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

Problem with some socket/event programming

7
I'm currently attempting to connect to a shoutcast server
pull down the information from here and then I'll parse it.

I got this working with the httplib, which was great, the problem is I want to use the select statement to do only do this periodically. (I'm trying to be a client, accepting data, that might be my first problem)

Basically this is the code that im working on to TEST to mimic what the httplib does, only return a socket object making select be able to use.

Event programming is fun :P


anyway here is the code im working on to send a request to the httpserver, bring down the info I want. (parsing and everything I already have control of ;) )

Expand|Select|Wrap|Line Numbers
  1.  
  2. import socket
  3.  
  4. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  5. socket.connect(('ip of the server here', portnum)
  6.  
  7. if sock.connect:
  8.       print "We connected!"
  9.  
  10. request = """
  11.  
  12. GET / HTTP/1.1
  13. User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7
  14. Connection: close
  15.  
  16. """
  17.  
  18. sock.send(request)
  19. data = sock.recv(1024)
  20.  
  21. print data
  22.  
  23. #####################
  24.  
  25. output ~> socket.error(104,'Connection reset by peer')
  26.  
So any advice to fix this would be great :D

Also, if any of you have any advice on event driven socket programming, I'd love to hear it. As you can tell, im fairly new to socket/event programming. Thanks so much guys!

~shonen
Mar 29 '07 #1
0 1699

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Tero Saarni | last post: by
reply views Thread by Gonçalo Rodrigues | last post: by
1 post views Thread by Andrew Arace | last post: by
4 posts views Thread by Haim | last post: by
2 posts views Thread by darthghandi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.