Client/Server Model#

pync can act as a client:

pync [options] dest port[s]

or a server:

pync -l [options] [dest] port

Once a connection has been established, any data read from stdin gets sent to the connection and any data received from the connection gets written to stdout:

stdin  --data-> connection
stdout <-data-- connection

To illustrate a very basic client/server model, you can connect two pync instances together to send messages back and forth.

  1. On one console, create a server to listen on a specific port:

pync -l 8000
py -m pync -l 8000
# server.py
import pync
pync.run('-l 8000')

pync is now listening for a connection on port 8000.

  1. On a separate console, connect to the server on the port being listened on:

pync localhost 8000
py -m pync localhost 8000
# client.py
import pync
pync.run('localhost 8000')

There should now be a connection between the two consoles and anything typed in one console should display in the other and vice-versa.

When finished, hit Ctrl+C from either console to close the connection.

What’s next?#

While sending messages back and forth isn’t all that interesting, this core concept of redirecting input and output, to and from the network, opens up a range of other possibilities:



SEE ALSO: