{ "metadata": { "name": "", "signature": "sha256:d05b62b1999f4ed595d5ac1f2e584a51917500ee9d1f1d66b12a56606017c51c" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import zmq\n", "import mmi\n", "\n", "# start client\n", "context = zmq.Context()\n", "socket = context.socket(zmq.REQ)\n", "\n", "socket.connect('tcp://127.0.0.1:9002')\n", "\n", "def send_and_receive(action, name=None, array=None, arguments=None):\n", " message = {}\n", " message['action'] = action\n", " if name:\n", " message['name'] = name\n", " if arguments:\n", " message['arguments'] = arguments\n", " mmi.send_array(socket, array, metadata=message)\n", " return mmi.recv_array(socket)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "send_and_receive('initialize')" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 7, "text": [ "(None, {u'timestamp': u'2014-04-22T14:58:25.621000'})" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "send_and_receive('update', arguments='{\"time_step\": 0.1}')" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 8, "text": [ "(None, {u'timestamp': u'2014-04-22T14:58:26.806000'})" ] } ], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "zk, m = send_and_receive('get_1d_double', 'xk')\n", "\n", "print m\n", "print zk[:10]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "{u'timestamp': u'2014-04-22T14:59:23.168000', u'shape': [299], u'dtype': u'float64'}\n", "[ 82.19255454 75.45917552 69.61489497 64.54231328 60.13953269\n", " 56.31811035 53.00128174 49.68445312 45.80405981 41.26434611]\n" ] } ], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "send_and_receive('finalize')" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 21, "text": [ "(None, {u'timestamp': u'2014-04-22T14:32:42.399000'})" ] } ], "prompt_number": 21 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }