Whoops…Nothing found

Try other keywords in your search

Trigger API via Python over TCP

 0 Minutes

 0 Likes

 181 Views

Python example (Thank you Benjamin Mueller from http://www.benni-m.de/):

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#server ip and port
server_address = ('127.0.0.1',1400)
print('connecting to %s port %s' %server_address)
#connect to server
sock.connect(server_address)

try:
    #message
    MESSAGE = b'{"jsonrpc":"2.0", "id":18, "method":"Pixera.Compound.setTransportModeOnTimelineAtIndex", 
                        "params":{"index":0, "mode":1}}0xPX'
    print("message: %s" % MESSAGE)
    #send
    sock.sendall(MESSAGE)

    #look for the response
    amount_received = 0
    amount_expected = 1024
    data = bytearray(0)
    pixDL = bytearray('0xPX','utf-8')
    while amount_received < amount_expected:
        data += sock.recv(1)
        amount_received += 1
        if len(data) > 4:
            if data[amount_received-4] == pixDL[0] 
            and data[amount_received-3] == pixDL[1]
            and data[amount_received-2] == pixDL[2] 
            and data[amount_received-1] == pixDL[3]:
                print('received %s' %data.decode('utf-8'))
                break
        

finally:
    print('closing socket')
    sock.close()


Was this article helpful?