Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Mar 28th, 2008, 10:13 AM   #1
terron
Newbie
 
Join Date: Mar 2008
Posts: 1
Rep Power: 0 terron is on a distinguished road
How do I reconnect a disconnected socket?

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:
python Syntax (Toggle Plain Text)
  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?
terron is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java socket Server compile errors.. n3o_X Java 3 Nov 18th, 2007 12:39 AM
Streaming Sound Over a Socket King C++ 3 Apr 7th, 2007 5:29 PM
how to check if the socket is still connected? myName C++ 1 Jun 14th, 2006 6:27 AM
Socket Server hbe02 C++ 19 May 23rd, 2006 10:14 PM
Socket problem Polyphemus_ C++ 3 Feb 28th, 2006 2:01 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:17 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC