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-29 0:13

Another question for the programmers of /prog/:

Say you have a data structure in C, and you have a function to malloc a new structure, and return it et cetera.

Do you create a function and get passed in a pointer to a pointer to a struct, or return a pointer to a struct:


int
ds_init(struct ds **ptr)
{
  *ptr = malloc(sizeof(**ptr));

  // Of course you can return more interesting integers for errors et cetera.
  return 1;
}


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