From 7aa248272fb7687f6cfd84a1414ddee4f0a47369 Mon Sep 17 00:00:00 2001 From: itraviv Date: Wed, 10 Aug 2016 16:09:04 +0300 Subject: ***this is an example for a JSON-RPC (over ZMQ) client.*** started with -s for server IP address (default is local-host) started with -p for port number --- .../examples/zmq_server_client.py | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 scripts/automation/trex_control_plane/examples/zmq_server_client.py (limited to 'scripts/automation/trex_control_plane/examples') diff --git a/scripts/automation/trex_control_plane/examples/zmq_server_client.py b/scripts/automation/trex_control_plane/examples/zmq_server_client.py new file mode 100755 index 00000000..15f37f1a --- /dev/null +++ b/scripts/automation/trex_control_plane/examples/zmq_server_client.py @@ -0,0 +1,45 @@ +import sys +import os +python2_zmq_path = os.path.abspath(os.path.join(os.pardir,os.pardir,os.pardir, + 'external_libs','pyzmq-14.5.0','python2','fedora18','64bit')) +sys.path.append(python2_zmq_path) +import zmq +import json +from argparse import * + +parser = ArgumentParser(description=' Runs a Scapy Server Client example ') +parser.add_argument('-p','--dest-scapy-port',type=int, default = 4507, dest='dest_scapy_port', + help='Select port to which this Scapy Server client will send to.\n default is 4507\n',action='store') +parser.add_argument('-s','--server',type=str, default = 'localhost', dest='dest_scapy_ip', + help='Remote server IP address .\n default is localhost\n',action='store') + +args = parser.parse_args() + +dest_scapy_port = args.dest_scapy_port +dest_scapy_ip = args.dest_scapy_ip + +context = zmq.Context() + +# Socket to talk to server +print 'Connecting:' +socket = context.socket(zmq.REQ) +socket.connect("tcp://"+str(dest_scapy_ip)+":"+str(dest_scapy_port)) +try: + while True: + command = raw_input("enter RPC command [enter quit to exit]:\n") + if (command == 'quit'): + break + user_parameter = raw_input("input for command [should be left blank if not needed]:\n") + json_rpc_req = { "jsonrpc":"2.0","method": command ,"params":[user_parameter], "id":"1"} + request = json.dumps(json_rpc_req) + print("Sending request in json format %s" % request) + socket.send(request) + + # Get the reply. + message = socket.recv() + print("Received reply %s [ %s ]" % (request, message)) +except KeyboardInterrupt: + print('Terminated By Ctrl+C') + socket.close() + context.destroy() + -- cgit 1.2.3-korg