resume TCP comunication

zunbeltz at gmail.com zunbeltz at gmail.com
Mon Nov 28 04:39:12 EST 2005


Hi,

I'am writing a program to cotrol a machine. I use socket comunication
(TCP) to do it.
I do a measurement in my machine like this:

def DoMeasurement():
    setup1()
    setup2()
    while MeasurementNotFinished():
        move()
        measure()
    finalizeMeasurement()


Each funciton setup1, setup2, move,mesure, ... call a method in a class
that contains a socket that do the comunication staff

class DiSock(socekt):
    self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    def comunicate(self):
        self.sock.sendall(Request.struct2string())

        msg = ''
        MSGLEN = 608
        while len(msg) < MSGLEN:
            chunk = self.sock.recv(MSGLEN-len(msg))
            if chunk == '':
                raise RuntimeError,"socket connection broken"
            msg = msg + chunk
        data = msg
        Answer.string2struct(data)


Request and Anser are objects in where i put the information i whant to
send and recive from the
machine.

All the measurement is done in a new thread.

The problem is that sometimes i loose the conenction whith the
machines. In the case a ConnectionFailure exception is raised. How can
i do resume the Measurement when the conection is  resumed? Can i use a
yield for this?

Thanks in advance

Zunbeltz




More information about the Python-list mailing list