Server
Detailed documentation of the ALS image server module
Categories:
Overview
The Server utility module exposes ALS processing results through a lightweight HTTP and WebSocket service.
It is responsible for:
- Publishing the latest stacked image and session metrics in the configured web folder
- Serving the viewer web application (
index.html, JavaScript and icons) - Streaming live new-image notifications to connected browsers over WebSockets
The module runs in its own asyncio event loop and accepts concurrent browser clients. It never alters the processing pipeline; it only serves the web image written by the Save module.
ℹ️ The server delivers the content stored in the web folder. By default, this folder is an alias of the
work folder; you can dedicate a separate folder from the Output preferences.
Configuration
| Setting | Source | Data Type | Required | Default Value |
|---|---|---|---|---|
| Web Folder | Preferences: Output Tab | Path to a folder | Yes | Work folder alias |
| Dedicated Web Folder | Preferences: Output Tab | Boolean | No | Disabled |
| Displayed Address | Preferences: Output Tab | String (auto or ip:<address>) |
Yes | Auto - recommended |
| Port Number | Preferences: Output Tab | Integer (1024–65535) | Yes | 8000 |
Control
| Source | Type | Response |
|---|---|---|
Main controls |
Command: START |
Prepare web assets and launch the server thread |
Main controls |
Command: STOP |
Notify clients and shut the server down. Keep web assets available on disk |
Outputs
Once started, the module maintains the following artefacts inside the web folder:
| Artefact | Description |
|---|---|
index.html |
The embedded viewer that displays the live stacked image |
favicon.ico & icons/*.png |
Viewer assets copied from the ALS resources bundle |
data.json |
Session metrics (STACK_SIZE, EXPO) refreshed after each stack update |
web_image.jpg |
Latest processed frame saved in JPEG for browser consumption |
openseadragon.min.js |
Deep-zoom viewer script used by the web interface |
Behavior
Startup sequence
- Publish static assets —
index.html, icons, and the waiting image are written (or refreshed) in the web folder so that first-time clients load instantly. - Expose session metrics —
data.jsonis generated with the current stack size and cumulative exposure time. - Validate availability — the module attempts the actual server bind on
0.0.0.0:<port>. APortInUseErroris raised if the configured port cannot be used. - Run the server loop — an asyncio loop starts in a dedicated thread, serves HTTP on all local IPv4 interfaces, and accepts WebSocket connections on
/ws. - Advertise availability — ALS resolves the configured Displayed Address preference and updates its UI with the selected address.
Binding and displayed address
The bind address and the displayed address are intentionally separate:
- The server binds to
0.0.0.0so it can accept connections through any available local IPv4 interface. - The Displayed Address is a concrete local address that another device can use to browse the image server.
If the selected Displayed Address is a loopback address, the module keeps running but reports that image server access is limited so that you can choose another Displayed Address when one is available.
Live updates
- After each processed image, the latest JPEG and
data.jsonare overwritten in the web folder. notify_browsers_about_new_image()pushes{ "type": "new_image" }to all WebSocket clients so that browsers reload the image without polling.- The same infrastructure is used to deliver
{ "type": "disconnect" }right before shutdown, allowing clients to display an appropriate message.
Shutdown
When the STOP command is triggered:
- All connected clients receive a
disconnectmessage. - The module waits briefly (2 seconds) for browsers to close the socket.
- The asyncio runner is cleaned up and the dedicated thread stops.
- UI status and QR code are reset; the static files remain on disk for the next session.
WebSocket reference
| Message | Payload | Trigger |
|---|---|---|
new_image |
{ "type": "new_image" } |
A freshly processed frame becomes available |
disconnect |
{ "type": "disconnect" } |
Server is shutting down |
Troubleshooting
- Change the port number in preferences if ALS reports that the port is already in use.
- If another device cannot browse the image server, select a Displayed Address that belongs to the same network as the browser device, then retry the URL or QR code.
- Check that your firewall allows inbound connections on the configured port.