yakshaveinc / linux

software engineering for Linux projects
The Unlicense
1 stars 3 forks source link

Debugging with echo over socket #31

Open abitrolly opened 4 years ago

abitrolly commented 4 years ago
  1. Open local socket to listen to incoming echoes.
    $ nc -Ulk /tmp/socket
    # -U  - open unix socket
    # -l  - open for listening
    # -k  - keep open for multiple connections
  2. Add echo function to Python code
    
    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)

abitrolly commented 4 years ago

Error for conn.connect on Unix socket.