An image containing a build of APE with a python socket interface
372
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.
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.
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)
Content type
Image
Digest
Size
84.7 MB
Last updated
about 5 years ago
docker pull haub/attempto-parser-socket