Attempting to reconnect socket fails

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 1
Reputation: terron is an unknown quantity at this point 
Solved Threads: 0
terron terron is offline Offline
Newbie Poster

Attempting to reconnect socket fails

 
0
  #1
Mar 27th, 2008
I'm trying to make something that once it is disconnected will automatically try to reconnect. I'll add some more features in later so it doesn't hammer the server but right now I just want to keep it simple and get that part working. The problem is that when I use sock.close I get an error message of
Bad File Descriptor
and if I either use shutdown or just go straight to reconnecting I get:
Transport endpoint is already connected
This is what I've got right now:
  1. #! /usr/bin/env python
  2. import socket, string
  3. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  4. def doconn():
  5. sock.connect(("localhost", 1234))
  6. def dodiscon():
  7. sock.close()
  8. doconn()
  9.  
  10. doconn()
  11.  
  12. while (1):
  13. buffer = sock.recv(1024)
  14. if not buffer:
  15. dodiscon()

What am I doing wrong?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC