TEXT 12
Socket.txt Guest on 6th April 2021 09:32:19 AM
  1. Sockets
  2. =======
  3.  
  4.  
  5. Data-stream interface
  6. ---------------------
  7.  
  8. A simple method to export data through the network. The MORSE sockets
  9. middleware will create one socket for each component. The service
  10. ``simulation.list_streams`` returns the list of available data streams, and the
  11. service ``simulation.get_stream_port(<stream name>)`` returns the port number
  12. associated to this stream.
  13.  
  14. Data is shared as JSON object, encoded in utf-8 strings. As such, when
  15. exchanging data with a particular component using this middleware, it is
  16. necessary to create a similar data structure to the ``local_data`` dictionary
  17. in the component.
  18. For example, when using telnet to connect to a
  19. :doc:`waypoint actuator <../actuators/waypoint>`, you need to send a message
  20. like the following::
  21.  
  22.   $ telnet localhost 60000
  23.   {"x":3.0, "y":5.0, "z":0.0, "tolerance":0.5, "speed":2.0}
  24.  
  25. The socket data-stream interface is implemented in :py:mod:`morse.middleware.socket_datastream`.
  26.  
  27. .. note:: The port numbers used for the socket datastream interface start at 60000.
  28.  
  29. .. _socket_ds_configuration:
  30.  
  31. Configuration specificities
  32. ---------------------------
  33.  
  34. There is no special configuration parameter for the socket middleware.
  35.  
  36. Service interface
  37. -----------------
  38.  
  39. Requests to components or MORSE itself can be sent through the socket interface.
  40.  
  41. The (ASCII) protocol is simple. Either::
  42.  
  43.   id component service [parameters]
  44.  
  45. or::
  46.  
  47.   id special
  48.  
  49. - ``id`` is a freely chosen request id. It is mainly useful to identify answers
  50.   from asynchronous services.  
  51. - ``component`` is the name of the component you want to invoke the service on.
  52.  
  53. .. note::
  54.   Services that control the whole simulator belong to the special component ``simulation``.
  55.  
  56. - ``service``: the name of the request to invoke.
  57. - ``parameters`` (can be omitted if the request takes no argument): request
  58.   arguments in JSON format. Arguments must be enclosed in a list (*i.e.*, inside
  59.   brackets).
  60. - ``special``: a special command, used to manipulate already existing requests.
  61.   Currently, the only special command is ``cancel`` (to abort a running
  62.   service)
  63.  
  64. MORSE answer follows this model::
  65.  
  66.   id status [result]
  67.  
  68. - ``id`` the same id the client used to send the request,
  69. - ``status``: one of the :py:mod:`morse.core.status` constants
  70. - ``result``: a JSON-serialized result, if any.
  71.  
  72. Example::
  73.  
  74.   $ telnet localhost 4000
  75.   Connected to localhost.
  76.   > req1 Human move [1.0, 2.0]
  77.   req1 OK
  78.  
  79. .. note:: The socket service interface listen by default on port 4000. If this
  80.       port is busy, MORSE will try to connect to the next 10 ports {4001-4010}
  81.       before giving up.
  82.  
  83. .. note:: Why 4000?? That's a good question! A free beer for the first one who finds out.
  84.  
  85. The socket service interface is implemented in :py:mod:`morse.middleware.socket_request_manager`.
  86.  
  87. Files
  88. -----
  89.  
  90. - Python (data-stream): ``$MORSE_ROOT/src/morse/middleware/socket_datastream.py``
  91. - Python (services): ``$MORSE_ROOT/src/morse/middleware/socket_request_manager.py``
  92.  
  93. .. _json: http://docs.python.org/library/json.html

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.