def _runserver(handshake_port):
    sock = zmq.Context().socket(zmq.REP)
    appport = sock.bind_to_random_port('tcp://127.0.0.1')

    handshakesock = zmq.Context().socket(zmq.REQ)
    handshakesock.connect('tcp://127.0.0.1:%s' % handshake_port)
    handshakesock.send(str(appport))
    handshakesock.recv() # acknowledgement
    handshakesock.close()

    while True:
        recved = sock.recv()
        func, arg = json.loads(recved)
        try:
            code = mayaserver.SUCCESS
            response = None
            if func == 'exec':
                executeInMainThreadWithResult(_exec, arg)
            elif func == 'eval':
                response = executeInMainThreadWithResult(
                    _eval, arg)
            else:
                code =  mayaserver.INVALID_METHOD
                response = func
            pickled = json.dumps([code, response])
        except Exception:
            pickled = json.dumps([
                mayaserver.UNHANDLED_ERROR,
                ''.join(traceback.format_exc())])
        sock.send(pickled)
dataset/ETHPy150Open rgalanakis/practicalmayapython/src/chapter6/mayaserver/server_gui.py/_runserver/original