This is a network server capable of handling request/reply style communication (using ZeroMQ). When running, it maintains a zeroconf entry (using avahi) so that it can be discovered automatically over LANs.
| Parameters: |
|
|---|
The handler can also be specified using the server.handler decorator:
>>> server = Server("Bob's Dungeon Game", "dungeon")
>>> @server.handler
... def on_request(msg):
... if msg == 'attack':
... return 'You attack a monster!'
... return 'Nothing happens.'
...
>>> server.run()
Decorator function which provides a more readable way of defining the handler for a server. Be aware that this will override any previously defined handler.
This is the counterpart to the Server. This client is capable of discovering servers on the LAN and connecting to them (or to any other server) using the same request/reply protocol (ZeroMQ).
| Parameters: | kind – The machine-readable kind of server you want to connect to. Currently only used by find_server(). |
|---|
Connect to a server. If you connect to multiple servers, ZeroMQ will load-balance between them.
| Parameters: | target – A ZeroMQ endpoint (e.g., “tcp://192.168.0.1:12345”) |
|---|
Find a server on the local network (using avahi) and (optionally) connect to it.
| Parameters: |
|
|---|---|
| Return type: | (string) The ZeroMQ endpoint of the chosen server. |
After sending a message to the server with .send_async(), calling this method will wait for the response from the server and return it.
| Return type: | string (the data returned from the server) |
|---|
Send a message to the server, wait for the response, and return it. Both the sent and received messages are binary strings, not unicode.
| Parameters: | data – The data to be sent to the server. |
|---|---|
| Return type: | string (the data returned from the server) |
Send a message to the server, without waiting for a response.
Currently this method waits for acknowledgement of the message by a server, but this extra latency will be removed in the future.
In order to get the result of the message, call .read_async.
| Parameters: | data – The data to be sent to the server. |
|---|