programming_intro.rst 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. .. _raet-programming:
  2. =========================
  3. Intro to RAET Programming
  4. =========================
  5. .. note::
  6. This page is still under construction
  7. The first thing to cover is that RAET does not present a socket api, it
  8. presents, and queueing api, all messages in RAET are made available to via
  9. queues. This is the single most differentiating factor with RAET vs other
  10. networking libraries, instead of making a socket, a stack is created.
  11. Instead of calling send() or recv(), messages are placed on the stack to be
  12. sent and messages that are received appear on the stack.
  13. Different kinds of stacks are also available, currently two stacks exist,
  14. the UDP stack, and the UXD stack. The UDP stack is used to communicate over
  15. udp sockets, and the UXD stack is used to communicate over Unix Domain
  16. Sockets.
  17. The UDP stack runs a context for communicating over networks, while the
  18. UXD stack has contexts for communicating between processes.
  19. UDP Stack Messages
  20. ==================
  21. To create a UDP stack in RAET, simply create the stack, manage the queues,
  22. and process messages:
  23. .. code-block:: python
  24. from salt.transport.road.raet import stacking
  25. from salt.transport.road.raet import estating
  26. udp_stack = stacking.StackUdp(ha=('127.0.0.1', 7870))
  27. r_estate = estating.Estate(stack=stack, name='foo', ha=('192.168.42.42', 7870))
  28. msg = {'hello': 'world'}
  29. udp_stack.transmit(msg, udp_stack.estates[r_estate.name])
  30. udp_stack.serviceAll()