By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,711 Members | 2,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,711 IT Pros & Developers. It's quick & easy.

Problem with some socket/event programming

P: 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
  2. import socket
  4. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  5. socket.connect(('ip of the server here', portnum)
  7. if sock.connect:
  8.       print "We connected!"
  10. request = """
  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
  16. """
  18. sock.send(request)
  19. data = sock.recv(1024)
  21. print data
  23. #####################
  25. output ~> socket.error(104,'Connection reset by peer')
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!

Mar 29 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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