TCP-Server that listens on a specified port for TCP-Connections. Every request sent to the server has to be one of the special commands described later on or a string of 0s and 1s each specifying a dot to be turned on or off respectively. For instance, to display the letter ‘T’ on a 4x3 display of this form
1111 0110 0110
the following request must be sent to the server: 111101100110.
A simple command line client like nc can send this request to ‘server’ listening on port 10101:
$ echo 111101100110 | nc server 10101
If the request contains the string ‘SIZE’ (ignoring case), the server will respond with the dimensions of the display (width x height).
Lets start a server. Here we use a thread in order to be able to run the client afterwards. In practice the server will run on a different platform and can be started directly.
>>> import net >>> import displayprovider >>> import threading >>> ds = net.DisplayServer(displayprovider.DisplayBase()) >>> th = threading.Thread(target=ds.start) >>> th.setDaemon(True) >>> th.start() Starting server for dimension 4 x 3 on 0.0.0.0 at port 10101
Now we can start a client and send some pixels to the server.
>>> cl = net.RemoteDisplay(host="0.0.0.0") Remote display will send data to 0.0.0.0 on port 10101 >>> cl.px(1, 1, True) >>> cl.px(2, 3, True) >>> cl.show() Listening on 0.0.0.0 at port 10101 received 12 bytes
The output lines after show() are coming from the server.
RemoteDisplay(host='0.0.0.0', port=10101, width=28, height=13)¶
Remote class to connect with a running display server.
px(x, y, val)¶