[Libwebsockets] How does lws send javascript code?!

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


Hi!

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:

  .mountpoint="/"
  .mountpoint_len=1
  .origin_protocol=LWSMPRO_FILE
  .def="index.html"
  .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
mountpoint="/index.html"
- 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!
Alexander.


More information about the Libwebsockets mailing list