$ nc -Ulk /tmp/socket
# -U - open unix socket
# -l - open for listening
# -k - keep open for multiple connections
import socket
conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
conn.connect('/tmp/socket')
# ^ this will fail if nobody is listening on Unix socket
def echo(msg):
conn.sendall(msg + '\n')
echo('--- start ---')
echo(sys.executable)
echofunction to Python code