0

I have a development where a click of a button on the client webpage initiates the server to move a motor connected to the server box by USB. What I would like is for the server to emit a message on receipt of the client request to acknowledge the move is taking place, make the motor move, then once the motor is in its final position and has stopped the server should emit a new message to that effect.

I thought I could get around this by having the client make the first change to the text on the page, then the server resets it when the move is complete, but I get a server connection error when ever i use a sleep (or an equivalent to check if the motor is still moving to the new position).

Is there a way around this?

Server side

def pos1_message(message):
    print '\rrow 1 buttons clicked:  ',
    received = "Moving to position %s' %message['data']
    print received
    emit('server response', {'data': received)

    time.sleep(5) #this mimics the time taken for the motor to move. It

    emit('server response', {'data': 'System ready'})

Client side

    socket.on('server response', function(msg) {
        $('#log').append('<br>' + $('<div/>').text('Received: '+ msg.data).html());
    });

EDIT

I have reduced the complicated project back to the most simple case and it kind of works. I made the client change the text, then emit, then the server emits and makes the text change back. All formatting (text changes, including all formatting of the text box colour) work, but I still end up with the following error:

error: [Errno 10053] An established connection was aborted by the software in your host machine.

followed by some other details. Seeing as though it does do what I need, is there a way to handle this specific message to it doesn't show?

Fonty
  • 239
  • 2
  • 11
  • The `time.sleep(5)` call will only work if you have monkey patched the standard library for eventlet or gevent, whichever you are using. Have you done that? – Miguel Grinberg May 27 '16 at 18:21
  • I had, stupidly, commented that out as at one stage it was trying to figure out what that did, exactly. Reinstating it fixed the issue. Thanks heaps. – Fonty May 28 '16 at 10:55

0 Answers0