Sign inSign up

haub/attempto-parser-socket

By haub

•Updated about 5 years ago

An image containing a build of APE with a python socket interface

Image
0

372

haub/attempto-parser-socket repository overview

⁠Attempto Parser Socket

⁠A quick and dirty socket interface for the Attempto Parser⁠

⁠About

This image was created as a workaround for the built-in socket interface for APE. The image contains a fresh build of APE that is accessed via a Socket Server written in Python.

⁠Instructions

To run the socket server, you need to make sure port 2767 is exposed using the -p command. Ex: docker run -p 2767:2767 Upon startup, the python server is started and is ready to accept commands via port 2767.

When writing to the socket, simply send it whatever options you would pass to the APE command-line tool. The delimiter for the end of a command is '^~^'

When that delimiter is read, the server stops accepting input and executes the command. The server will then try to write the response to the client.

⁠Example Client
import socket

def sendMsg(s, msg):
    msg = msg.encode('utf-8')
    delimiter = '^~^'.encode('utf-8')

    s.send(msg + delimiter)

def recvMsg(s):
    msg = ''
    while not msg.endswith('^~^'):
        pkt = s.recv(1024).decode('utf-8')
        print('recieved packet: ' + pkt)
        msg += pkt
        break

    print("Recieved Message: " + msg[0:-3])
    return msg[0:-3]  


# create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

# get local machine name
host = socket.gethostname()                           

port = 2767

# connection to hostname on the port.
s.connect((host, port))          

# Ex: -text "John waits." -cdrsxml -csyntax
msg = input()

sendMsg(s, msg)
msg = recvMsg(s)
                                   
s.close()
print (msg)

Tag summary

Content type

Image

Digest

Size

84.7 MB

Last updated

about 5 years ago

docker pull haub/attempto-parser-socket