All server examples with descriptions and run commands.
Demonstrates a TCP Modbus server with derive-model based app wiring.
cargo run -p modbus-rs --example modbus_rs_server_tcp_demoSource: modbus-rs/examples/server/network-tcp/sync/demo.rs
Demonstrates a TCP server app using shared state patterns.
cargo run -p modbus-rs --example modbus_rs_server_std_transport_client_demoSource: modbus-rs/examples/server/network-tcp/sync/shared_state.rs
Demonstrates a sync server app that routes FC18 through fifo(...) and
FC14/FC15 through file_record(...) using #[modbus_app(...)].
cargo run -p modbus-rs --example fifo_file_record_demo \
--features server,network-tcp,fifo,file-recordSource: modbus-rs/examples/server/network-tcp/sync/fifo_file_record_demo.rs
Demonstrates a shared-state async TCP server using #[async_modbus_app] and
AsyncTcpServer::serve_shared. A background task simulates live register changes
so connected clients observe updating data.
cargo run -p modbus-rs --example modbus_rs_server_async_tcp_demo \
--features server,async,network-tcp,coils,holding-registers,input-registersSource: modbus-rs/examples/server/network-tcp/async/demo.rs
Demonstrates implementing [AsyncTrafficNotifier] to intercept all raw ADU frames
(TX, RX, framing errors, transmit errors) and the on_exception callback.
cargo run -p modbus-rs --example modbus_rs_server_async_tcp_traffic \
--features server,async,network-tcp,coils,holding-registers,trafficSource: modbus-rs/examples/server/network-tcp/async/traffic.rs
Demonstrates a full async TCP server that routes FC18 through fifo(...) and
FC14/FC15 through file_record(...) using #[async_modbus_app(...)], with a
background task that updates the served data.
cargo run -p modbus-rs --example modbus_rs_server_async_fifo_file_record_demo \
--features server,async,network-tcp,fifo,file-recordSource: modbus-rs/examples/server/network-tcp/async/fifo_file_record_demo.rs
cargo run -p modbus-rs --example modbus_rs_server_serial_rtu_demoSource: modbus-rs/examples/server/serial-rtu/sync/demo.rs
cargo run -p modbus-rs --example modbus_rs_server_serial_rtu_manual_no_macrosSource: modbus-rs/examples/server/serial-rtu/sync/manual_app_no_macros.rs
cargo run -p modbus-rs --example modbus_rs_server_serial_ascii_demo \
--features serial-ascii,coils,holding-registers,input-registersSource: modbus-rs/examples/server/serial-ascii/sync/demo.rs
Run a server in one terminal:
cargo run -p modbus-rs --example modbus_rs_server_tcp_demoAnd test with a client in another:
# Read coils (CLI host/port aware)
cargo run -p modbus-rs --example modbus_rs_client_tcp_backoff_jitter -- 127.0.0.1 5502 1
# Read/write registers
cargo run -p modbus-rs --example modbus_rs_client_tcp_registers -- 127.0.0.1 5502 1Expected server startup output includes:
Modbus TCP demo server listening on 127.0.0.1:5502
Unit id: 1
Supported now: FC01, FC03, FC04, FC05, FC06, FC0F, FC10, FC17
Note: modbus_rs_client_tcp_coils is currently hardcoded to a fixed host/port and does not use CLI host/port args.
- Sync Server Applications — Full poll-driven development guide
- Feature Flags — Customize your build
- Macros — Derive macro reference