A simple channel implementation for python for prototyping and debugging. It is thread-safe.
Args:
<host>
: The IP address to listen on.<port>
: The TCP port to listen on.reuse=True
: If set to true, it will set theSO_REUSEPORT
socket flag (which you generally want while debugging).echo=False
: If set to true, it will print basic information about connecting clients toSTDOUT
.
Return value: An iterator over the connecting clients. See below for an example.
Args:
<host>
: The IP address to connect to.<port>
: The TCP port to connect using.
Return value: A channel object connected to the given <host>
and <port>
.
Sends the given string to the other end of the channel which can be received with an equivalent call to recv()
.
send()
s are recv()
d in-order.
Receives the next string that was sent over this channel.
for client_channel in Channel.listen("localhost", 5000, reuse=True):
spin_off_client_thread(client_channel)
chan = Channel.connect("localhost", 5000)
chan.send("Hello World")
resp = chan.recv()
print resp