[Libwebsockets] How does lws send javascript code?!

Alexander Zvyagin zvyagin.alexander at gmail.com
Sat Jul 27 11:10:11 CEST 2019


I would like to understand how LWS sends javascript code to a client.

In my application the "client" code consists of two files:

  index.html  (size=400 Bytes)
  main.js (size=4 MBytes)

And the "index.html" has the line:

  <script type="text/javascript" src="main.js"></script></body>

The "server" code defines lws_http_mount structure with attributes:

  .origin="some/path"  (a directory with "index.html" and "main.js" files)

My _guess_ is that the logic is:

- a client connects to the server with mountpoint="/" OR
- the server sends back the "index.html" file
- the client (a web browser) gets "index.html", sees src="main.js" and
asks the server to send the file content
- the server gets the request on "main.js" files and because it is
allowed to serve the files (origin_protocol=LWSMPRO_FILE) and the
directory (origin="some/path") contains that file, it reads the file
and sends it back to the client.
- finally the client has both "index.html" and "main.js" files (the
latter will initialize the websocket connection with the server)

Am I right?

Thanks a lot in advance!

More information about the Libwebsockets mailing list