# along with this program. If not, see <http://www.gnu.org/licenses/> # # Source on github: # https://github.com/tbleiker/StreamBug # import multiprocessing import time import zmq from streambug import cmd_interface from streambug import mplogger # set up logging mplogger.setup(debug=True) log = mplogger.getLogger() def server_thread(zeromq_context, address, port_pull, port_pub): server = cmd_interface.Server(zeromq_context, address, port_pull, port_pub) server.start() time2wait = 0.5 # wait for client to come up time.sleep(time2wait) log.info('### Test 1: Request help.') server.send('help', 'c1', 'f1', 1) time.sleep(time2wait) log.info('### Test 2: Do not send a command:')
A client can be either a 'commander' or a 'follower'. A follower provides functions which can be called by a commander. A follower can also send update information to all connected commanders. """ import datetime import msgpack import threading import time import queue import zmq from streambug import mplogger log = mplogger.getLogger(__name__) # todo: replace 'commander' and 'follower' by the following constants: COMMANDER = 'commander' FOLLOWER = 'follower' def msg_encode(msg): """Encode message with msgpack.""" return msgpack.packb(msg, use_bin_type=True) def msg_decode(msg_pack): """Decode message with msgpack.""" return msgpack.unpackb(msg_pack, encoding='utf-8', use_list=False)