Hmm well i think you may find it is because when you call socket.close()
your socket becomes blank so to speak.
#! /usr/bin/env python
import socket, string
def doconn():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 1234))
def dodiscon():
sock.close()
doconn()
doconn()
while (1):
buffer = sock.recv(1024)
if not buffer:
dodiscon()
and so by moving the declaration of your socket into your doconn() function everytime you try to connect it re-defines the socket.
I thinks this works anyway plus i've no doubt been talking aload of rubbish but there we go
Chris