First and foremost, we'll need to define a listener, as this will need to be started first on our system. We import the Listener class from the multiprocessing.connection module, and then define an address tuple which takes in 'localhost' and 6000, which will be our port.
We then use Listener as a context manager, and wait to accept a connection on this port. Note that we set authkey=b'secret password'--this is to ensure that we don't receive information from rogue processes, but only from separate processes that connect to this address and port with the correct authkey:
from multiprocessing.connection import Listener
from array import array
address = ('localhost', 6000) # family is deduced to be 'AF_INET'
with Listener(address, authkey=b'secret password') as listener:
with listener.accept() as conn:
print('connection accepted from', listener.last_accepted)
conn.send([2.25, None, 'junk', float])
conn.send_bytes(b'hello')
conn.send_bytes(array('i', [42, 1729]))