Skip to content

Commit 86ba16e

Browse files
authored
[docs] Fix formatting in networking.rst. NFC (#16027)
Aside from general formatting this change also fixes some use of single backticks where double backticks were needed.
1 parent 7240c3d commit 86ba16e

File tree

1 file changed

+65
-17
lines changed

1 file changed

+65
-17
lines changed
Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,98 @@
11
.. Networking:
22
3-
==============================
3+
==========
44
Networking
5-
==============================
5+
==========
66

7-
Emscripten compiled applications have a number of ways to connect with online servers. Check the subtopics here to learn about the different strategies that are available.
7+
Emscripten compiled applications have a number of ways to connect with online
8+
servers. Check the subtopics here to learn about the different strategies that
9+
are available.
810

9-
If you are familiar with networking concepts provided by different web APIs, such as XmlHttpRequest, Fetch, WebSockets and WebRTC, you can quickly get started by leveraging what you already know: by calling out from C/C++ code to JavaScript (see the "Connecting C++ and JavaScript" section), you can establish networked connections by writing regular JavaScript. For C/C++ developers, Emscripten provides a few approaches, described here.
11+
If you are familiar with networking concepts provided by different web APIs,
12+
such as XmlHttpRequest, Fetch, WebSockets and WebRTC, you can quickly get
13+
started by leveraging what you already know: by calling out from C/C++ code to
14+
JavaScript (see the "Connecting C++ and JavaScript" section), you can establish
15+
networked connections by writing regular JavaScript. For C/C++ developers,
16+
Emscripten provides a few approaches, described here.
1017

1118
Emscripten WebSockets API
1219
=========================
1320

14-
WebSockets API provides connection-oriented message-framed bidirectional asynchronous networking communication to the browser. It is the closest to TCP on the web that web sites can access, direct access to TCP sockets is not possible from web browsers.
21+
WebSockets API provides connection-oriented message-framed bidirectional
22+
asynchronous networking communication to the browser. It is the closest to TCP
23+
on the web that web sites can access, direct access to TCP sockets is not
24+
possible from web browsers.
1525

16-
Emscripten provides a passthrough API for accessing the WebSockets API from C/C++ code. This is useful for developers who would prefer not to write any JavaScript code, or deal with the C/C++ and JavaScript language interop. See the system include file <emscripten/websocket.h> for details. One benefit that the Emscripten WebSockets API provides over manual WebSockets access in JavaScript is the ability to share access to a WebSocket handle across multiple threads, something that can be time consuming to develop from scratch.
26+
Emscripten provides a passthrough API for accessing the WebSockets API from
27+
C/C++ code. This is useful for developers who would prefer not to write any
28+
JavaScript code, or deal with the C/C++ and JavaScript language interop. See the
29+
system include file ``<emscripten/websocket.h>`` for details. One benefit that
30+
the Emscripten WebSockets API provides over manual WebSockets access in
31+
JavaScript is the ability to share access to a WebSocket handle across multiple
32+
threads, something that can be time consuming to develop from scratch.
1733

18-
To target Emscripten WebSockets API, you must link it in with a "-lwebsocket.js" linker directive.
34+
To target Emscripten WebSockets API, you must link it in with a
35+
``-lwebsocket.js`` linker directive.
1936

2037
Emulated POSIX TCP Sockets over WebSockets
2138
==========================================
2239

23-
If you have existing TCP networking code written in C/C++ that utilizes the Posix Sockets API, by default Emscripten attempts to emulate such connections to take place over the WebSocket protocol instead. For this to work, you will need to use something like WebSockify on the server side to enable the TCP server stack to receive incoming WebSocket connections. This emulation is not very complete at the moment, it is likely that you will run into problems out of the box and need to adapt the code to work within the limitations that this emulation provides.
24-
25-
This is the default build mode for Emscripten. Use the linker flag `-s WEBSOCKET_URL` or `Module['websocket']['url']` to specify the WebSocket URL to connect to, and the linker flag `-s WEBSOCKET_SUBPROTOCOL` or `Module['websocket']['subprotocol']` to control the connection type ('binary' or 'text').
40+
If you have existing TCP networking code written in C/C++ that utilizes the
41+
Posix Sockets API, by default Emscripten attempts to emulate such connections to
42+
take place over the WebSocket protocol instead. For this to work, you will need
43+
to use something like WebSockify on the server side to enable the TCP server
44+
stack to receive incoming WebSocket connections. This emulation is not very
45+
complete at the moment, it is likely that you will run into problems out of the
46+
box and need to adapt the code to work within the limitations that this
47+
emulation provides.
48+
49+
This is the default build mode for Emscripten. Use the linker flag ``-s
50+
WEBSOCKET_URL`` or ``Module['websocket']['url']`` to specify the WebSocket URL
51+
to connect to, and the linker flag ``-sWEBSOCKET_SUBPROTOCOL`` or
52+
``Module['websocket']['subprotocol']`` to control the connection type
53+
(``'binary'`` or ``'text'``).
2654

2755
Full POSIX Sockets over WebSocket Proxy Server
2856
==============================================
2957

30-
Emscripten provides a native POSIX Sockets proxy server program, located in directory tools/websocket_to_posix_proxy/, that allows full POSIX Sockets API access from a web browser. This support works by proxying all POSIX Sockets API calls from the browser to the Emscripten POSIX Sockets proxy server (via transparent use of WebSockets API), and the proxy server then performs the native TCP/UDP calls on behalf of the page. This allows a web browser page to run full TCP & UDP connections, act as a server to accept incoming connections, and perform host name lookups and reverse lookups. Because all API calls are individually proxied, this support can be slow. This support is mostly useful for developing testing infrastructure and debugging.
58+
Emscripten provides a native POSIX Sockets proxy server program, located in
59+
directory ``tools/websocket_to_posix_proxy/``, that allows full POSIX Sockets
60+
API access from a web browser. This support works by proxying all POSIX Sockets
61+
API calls from the browser to the Emscripten POSIX Sockets proxy server (via
62+
transparent use of the WebSockets API), and the proxy server then performs the
63+
native TCP/UDP calls on behalf of the page. This allows a web browser page to
64+
run full TCP & UDP connections, act as a server to accept incoming connections,
65+
and perform host name lookups and reverse lookups. Because all API calls are
66+
individually proxied, this support can be slow. This support is mostly useful
67+
for developing testing infrastructure and debugging.
3168

3269
The following POSIX sockets functions are proxied in this manner:
33-
- `socket()`, `socketpair()`, `shutdown()`, `bind()`, `connect()`, `listen()`, `accept()`, `getsockname()`, `getpeername()`, `send()`, `recv()`, `sendto()`, `recvfrom()`, `sendmsg()`, `recvmsg()`, `getsockopt()`, `setsockopt()`, `getaddrinfo(), `getnameinfo()`.
70+
- ``socket()``, ``socketpair()``, ``shutdown()``, ``bind()``, ``connect()``, ``listen()``, ``accept()``, ``getsockname()``, ``getpeername()``, ``send()``, ``recv()``, ``sendto()``, ``recvfrom()``, ``sendmsg()``, ``recvmsg()``, ``getsockopt()``, ``setsockopt()``, ``getaddrinfo()``, ``getnameinfo()``.
3471

3572
The following POSIX sockets functions are currently not proxied (and will not work):
36-
- `poll()`, `close()` (use `shutdown()` instead), `select()`
73+
- ``poll()``, ``close()`` (use ``shutdown()`` instead), ``select()``
3774

38-
To use POSIX sockets proxying, link the application with flags "-lwebsocket.js -s PROXY_POSIX_SOCKETS=1 -s USE_PTHREADS=1 -s PROXY_TO_PTHREAD=1". That is, POSIX sockets proxying builds on top of the Emscripten WebSockets library, and requires multithreading and proxying the application main() to a pthread.
75+
To use POSIX sockets proxying, link the application with flags ``-lwebsocket.js
76+
-sPROXY_POSIX_SOCKETS=1 -sUSE_PTHREADS=1 -sPROXY_TO_PTHREAD=1``. That is,
77+
POSIX sockets proxying builds on top of the Emscripten WebSockets library, and
78+
requires multithreading and proxying the application ``main()`` to a pthread.
3979

40-
For an example of how the POSIX Sockets proxy server works in an Emscripten client program, see the file tests/websocket/tcp_echo_client.cpp.
80+
For an example of how the POSIX Sockets proxy server works in an Emscripten
81+
client program, see the file ``tests/websocket/tcp_echo_client.cpp``.
4182

4283
XmlHttpRequests and Fetch API
4384
=============================
4485

45-
For HTTP transfers, one can use the browser built-in XmlHttpRequest (XHR) API and the newer Fetch API. These can be accessed directly from JavaScript. Emscripten also provides passthrough APIs to perform HTTP requests. For more information, see the emscripten_async_wget*() C API and the Emscripten Fetch API.
86+
For HTTP transfers, one can use the browser built-in XmlHttpRequest (XHR) API
87+
and the newer Fetch API. These can be accessed directly from JavaScript.
88+
Emscripten also provides passthrough APIs to perform HTTP requests. For more
89+
information, see the ``emscripten_async_wget*()`` C API and the Emscripten Fetch
90+
API.
4691

4792
WebRTC and UDP
4893
==============
4994

50-
Direct UDP communication is not available in browsers, but as a close alternative, the WebRTC specification provides a mechanism to perform UDP-like communication with WebRTC Data Channels. Currently Emscripten does not provide a C/C++ API for interacting with WebRTC.
95+
Direct UDP communication is not available in browsers, but as a close
96+
alternative, the WebRTC specification provides a mechanism to perform UDP-like
97+
communication with WebRTC Data Channels. Currently Emscripten does not provide a
98+
C/C++ API for interacting with WebRTC.

0 commit comments

Comments
 (0)