resume TCP comunication

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zunbeltz@gmail.com

    #1

    resume TCP comunication

    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 MeasurementNotF inished():
    move()
    measure()
    finalizeMeasure ment()


    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(s ocket.AF_INET, socket.SOCK_DGR AM)
    def comunicate(self ):
    self.sock.senda ll(Request.stru ct2string())

    msg = ''
    MSGLEN = 608
    while len(msg) < MSGLEN:
    chunk = self.sock.recv( MSGLEN-len(msg))
    if chunk == '':
    raise RuntimeError,"s ocket connection broken"
    msg = msg + chunk
    data = msg
    Answer.string2s truct(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 ConnectionFailu re 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

Working...