Rust Server Integration

Overview
The application includes integration with a Rust server through HTTP communication. While the Replit project contains the Python side of this integration, the Rust server itself is a separate application that must be running externally.

Architecture


┌─────────────────────┐
│  Python Bridge      │
│  (stream_bridge_    │
│   http_*.py)        │
└──────────┬──────────┘
           │ HTTP POST/GET
           ↓
┌─────────────────────┐
│  Rust Server        │
│  (rust-app.exe)     │
│  Port: 5000         │
└─────────────────────┘
           ↑
           │ HTTP GET
┌──────────┴──────────┐
│  Streamlit App      │
│  (HTTP Handler)     │
└─────────────────────┘

Rust Server Requirements

The Rust server must be running athttp://localhost:5000and provide the following endpoints:

1. Health Check Endpoint
GET /health
Response: 200 OK

Used by both the Python bridge and Streamlit app to verify server availability.

2. Data Storage Endpoint
POST /data/{key}
Headers: Content-Type: text/plain
Body: 
Response: JSON confirmation

The Python bridge stores data with keys like "python_message".

3. Data Retrieval Endpoint
GET /data/python_message
Response: 

The Streamlit app polls this endpoint to retrieve messages.

4. Cryptographic Operations Endpoint (Optional)
POST /crypto
Headers: Content-Type: application/json
Body: {"operation": "random_hex|sha256", "data": "...", "length": ...}
Response: {"success": true, "data": {"result": "..."}}

Supports operations like random hex generation and SHA256 hashing.

Python Bridge Script

File:attached_assets/stream_bridge_http_1757249928257.py

This script acts as a bridge between Modbus TCP data and the Rust server:

  1. Runs a Modbus TCP Server on127.0.0.1:12345
  2. Generates random register values (simulates industrial data)
  3. Sends data to Rust server via HTTP POST to /data/python_message
  4. Formats data as: [array_of_values]_timestamp

Example Message Format:

[45, 23, 78, 12, 0, 16256]_2025-10-05 14:30:22

Setting Up Rust Integration

Step 1: Start the Rust Server
# Navigate to your Rust application directory
cd path/to/rust-app
cargo run
# Or run the compiled executable
./rust-app.exe

The server must be listening on port 5000.

Step 2: Verify Rust Server
curl http://localhost:5000/health

Should return 200 OK.

Step 3: Run the Python Bridge (Optional)
python attached_assets/stream_bridge_http_1757249928257.py

This will:

  • Check if Rust server is running
  • Start Modbus server
  • Begin sending data to Rust server every few seconds
Step 4: Connect Streamlit App to Rust Server
  1. Select HTTP protocol in the dropdown
  2. Configure:
    • Host:localhost
    • Port:5000
    • Poll Interval:5 seconds (or desired interval)
  3. Click Connect
  4. Data from the Python bridge will appear in the message panel

Rust Server Data Flow

  1. Python Bridge → Reads Modbus data → Sends to Rust server(/data/python_message)
  2. Rust Server → Stores the message in memory/database
  3. Streamlit HTTP Handler → Polls Rust server (/data/python_message) → Displays in UI

Expected Rust Server Behavior

  • Store and retrieve data with key-value pairs
  • Handle concurrent requests from both bridge script and Streamlit app
  • Return latest datawhen polled
  • Optional:Provide cryptographic operations for data processing

Protocol Configuration Guide

MQTT Configuration

Field Description Example
Broker Host MQTT broker address broker.emqx.io
Port MQTT broker port 1883
Client ID Unique client identifier streamlit_client_123
Username Authentication username (optional) user
Password Authentication password (optional) pass
Keep Alive Authentication username (optional) 60
Topic Topic to subscribe to sensor/temperature

Connection Flow:

  1. Enter broker details
  2. Click Connect - status shows "Connecting..."
  3. Wait for "🟢 Connected" status
  4. Enter topic name
  5. ClickSubscribe to receive messages

HTTP/REST Configuration

Field Field Example
Server Host REST API server address localhost
Port Server port 5000
Poll Interval Seconds between data polls 5

Recommended for: Rust server integration, REST APIs, web services

Data Retrieval:

  • Polls /data/python_message endpoint
  • Parses bridge script format: [array]_timestamp
  • Displays Modbus registers and timestamps

Modbus TCP Configuration

Field Description Example
Modbus Host Device IP address 127.0.0.1
Port Modbus TCP port 12345
Unit ID Modbus unit/slave ID 1
Start Address First register address 0
Register Count Number of registers to read 10
Poll Interval Seconds between polls 2

Use Cases:

  • Industrial PLCs
  • SCADA systems
  • Modbus-enabled sensors
  • Test with Python bridge script (creates local Modbus server)

Video Streaming Configuration

Webcam Stream
Field Description
Stream Type Select "webcam"
No additional configuration needed
MJPEG Stream
Field
Description
Example
Stream Type Select "mjpeg"
MJPEG URL Camera MJPEG endpoint http://192.168.1.100/video.mjpg
RTSP Stream
Field
Description
Example
Stream Type Select "rtsp"
RTSP URL Camera RTSP feed rtsp://192.168.1.100:554/stream

Advanced Settings:

  • Enable Frame Processing: Log frame statistics
  • Processing Log Interval: Frames between logs (default: 30)