nn_ws.adoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. nn_ws(7)
  2. ========
  3. NAME
  4. ----
  5. nn_ws - WebSocket transport mechanism
  6. SYNOPSIS
  7. --------
  8. *#include <nanomsg/nn.h>*
  9. *#include <nanomsg/ws.h>*
  10. DESCRIPTION
  11. -----------
  12. The WebSocket transport uses the framing protocol specified in RFC 6455 to
  13. transport messages. The initial handshake is done using HTTP headers, with the
  14. `Sec-Websocket-Protocol` header set to the SP protocol used by the server.
  15. For example, a REQ client will send `rep.sp.nanomsg.org`.
  16. Each SP message is transported in a single WebSocket frame, with no additional
  17. data or headers applied. By default this library sends and expects to receive
  18. binary frames.
  19. When calling either `nn_bind()` or `nn_connect()`, omitting the port defaults
  20. to the RFC 6455 default port 80 for HTTP. For example, `ws://127.0.0.1` is
  21. equivalent to `ws://127.0.0.1:80`
  22. WebSocket over TLS is not supported by this library, at this time.
  23. URI limitations
  24. ~~~~~~~~~~~~~~~
  25. When calling `nn_connect()`, the URI may also optionally include the path to a
  26. resource and/or query parameters.
  27. .Path and query parameters
  28. ==========================
  29. s1 = nn_socket (AF_SP, NN_PAIR);
  30. nn_connect (s1, "ws://example.com/path?query=value");
  31. ==========================
  32. This implementation includes the full path and any query parameters in the
  33. HTTP handshake when establishing connections with `nn_connect()`. This
  34. information is not available via the nanomsg API afterwards, however.
  35. Likewise, this implementation does not examine or use either any path or
  36. query parameters that may be supplied to `nn_bind()`, as it only binds to
  37. the TCP port. This implementation acts as a limited HTTP server that offers
  38. SP over WebSocket at all URIs for the given TCP address.
  39. Applications, however, should not depend on this behavior; intervening
  40. infrastructure may proxy, filter or route based on URI, and other
  41. implementations of the SP over WebSocket protocol may offer other
  42. HTTP services at the same TCP port, utilizing the path, query parameters,
  43. or both to determine the service to be used.
  44. Socket Options
  45. ~~~~~~~~~~~~~~
  46. NN_WS_MSG_TYPE::
  47. This option may be set to NN_WS_MSG_TYPE_TEXT or NN_WS_MSG_TYPE_BINARY.
  48. The value of this determines whether data messages are sent as WebSocket
  49. text frames, or binary frames, per RFC 6455. Text frames should contain
  50. only valid UTF-8 text in their payload, or they will be rejected. Binary
  51. frames may contain any data. Not all WebSocket implementations support
  52. binary frames. The default is to send binary frames.
  53. +
  54. This option may also be specified as control data when when sending
  55. a message with `nn_sendmsg()`.
  56. TODO: NN_TCP_NODELAY::
  57. This option, when set to 1, disables Nagle's algorithm. It also disables
  58. delaying of TCP acknowledgments. Using this option improves latency at
  59. the expense of throughput. Type of this option is int. Default value is 0.
  60. EXAMPLE
  61. -------
  62. ----
  63. nn_bind (s1, "ws://*:5555");
  64. nn_connect (s2, "ws://myserver:5555");
  65. ----
  66. SEE ALSO
  67. --------
  68. <<nn_tcp#,nn_tcp(7)>>
  69. <<nn_inproc#,nn_inproc(7)>>
  70. <<nn_ipc#,nn_ipc(7)>>
  71. <<nn_bind#,nn_bind(3)>>
  72. <<nn_connect#,nn_connect(3)>>
  73. <<nanomsg#,nanomsg(7)>>
  74. AUTHORS
  75. -------
  76. link:mailto:sustrik@250bpm.com[Martin Sustrik]
  77. link:mailto:jack@wirebirdlabs.com[Jack R. Dunaway]
  78. link:mailto:garrett@damore.org[Garrett D'Amore]