Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I fail at python sockets, hard

Name: Anonymous 2008-03-28 9:30

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:

#! /usr/bin/env python
import socket, string
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def doconn():
    sock.connect(("localhost", 1234))
def dodiscon():
    sock.close()
    doconn()

doconn()

while (1):
    buffer = sock.recv(1024)
    if not buffer:
        dodiscon()


What am I doing wrong?

Name: Anonymous 2008-03-28 23:32

While we're on the topic of sockets, I have a question for [spoiler]/prog/[spoiler]:

Say your UNIX application connects to some server, and is doing normal read and write stuff, and then suddenly the socket dies. What do you do? Do you try to reconnect, or do you abort the whole program with an error? Maybe you do some hybrid approach that tries to reconnect a couple times at increasing intervals of time, and then abort after a while.

Well [spoiler]/prog/[spoiler], tell me.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List