Quickstart
In this walkthrough, you’ll run two small programs. One broadcasts an Entity State PDU for a tank once a second. The other listens for PDUs and prints what it hears. This walkthrough takes about 5 minutes.
Both programs live in the repository’s examples directory. You can run them from a
clone of the repository, as shown at the end of this page, or copy them into your
own project.
1. Send an Entity State PDU
An Entity State PDU is the heartbeat of DIS. Every simulator sends one for each entity it owns, at regular intervals, so that everyone else knows where that entity is and what it is doing.
// open-dis-rust - Rust implementation of the IEEE 1278.1-2012 Distributed Interactive
// Simulation (DIS) application protocol
// Copyright (C) 2026 Cameron Howell
//
// Licensed under the BSD 2-Clause License
use std::{error::Error, net::UdpSocket, thread, time::Duration};
use open_dis_rust::prelude::*;
use open_dis_rust::{
entity_information::EntityStatePdu,
records::{
EntityIdentifier, EntityMarking, EntityType, ExerciseIdentifier, Vector, WorldCoordinates,
},
siso::enums::{Country, DeadReckoningAlgorithm, EntityKind, ForceId},
};
fn main() -> Result<(), Box<dyn Error>> {
// Bind to any free local port and send to a receiver on port 3000.
let socket = UdpSocket::bind("0.0.0.0:0")?;
socket.connect("127.0.0.1:3000")?;
// Build an Entity State PDU describing one tank.
let mut pdu = EntityStatePdu::new();
pdu.header_mut().exercise_id = ExerciseIdentifier::new(1);
let simulation_address = SimulationAddress::new(1, 1);
pdu.entity_id = EntityIdentifier::new(simulation_address, 1); // site 1, application 1, entity 1
pdu.force_id = ForceId::Friendly;
// 1:1:225:1:1:3:0 is the SISO-REF-010 entity type for an M1A2 Abrams.
pdu.entity_type = EntityType::new(
EntityKind::Platform,
1,
Country::UnitedStatesofAmerica,
1,
1,
3,
0,
);
pdu.entity_marking =
EntityMarking::from_ascii("TANK01").ok_or("a marking is up to 11 ASCII characters")?;
pdu.entity_linear_velocity = Vector::new(10.0, 0.0, 0.0); // m/s, world frame
pdu.dead_reckoning_parameters.dead_reckoning_algorithm =
DeadReckoningAlgorithm::DRMConstantVelocityLowAccelerationLinearMotionEntity;
// Location is geocentric (ECEF) meters. This point is on the equator at 0 degrees longitude.
let mut x = 6_378_137.0;
for _ in 0..10 {
pdu.entity_location = WorldCoordinates::new(x, 0.0, 0.0);
pdu.header_mut().timestamp = Timestamp::now();
// serialize() fills in the PDU type, family, length and all counts.
let bytes = pdu.to_bytes()?;
socket.send(&bytes)?;
println!("sent {}-byte Entity State PDU, x = {x:.1}", bytes.len());
x += 10.0;
thread::sleep(Duration::from_secs(1));
}
Ok(())
}
A few things to notice:
EntityStatePdu::new()gives you a PDU with sensible defaults and the header already set up. You only fill in the fields you care about.- Entity IDs consist of three numbers: site, application, and entity IDs. Together they must be unique within the exercise. It should be noted that this crate does NOt enforce this constraint. That is completely up to the consumer to ensure uniqueness.
- Entity types come from the SISO-REF-010 enumerations.
- Locations are geocentric (ECEF) coordinates in meters.
to_bytes()(andserialize()) fills in the PDU type, protocol family, length, and every count field before encoding. You should not have to fill outheader.lengthyourself.
2. Receive and decode PDUs
The receiver binds to UDP port 3000, which is traditionally the port used for DIS
traffic per the standard. It decodes each datagram with AnyPdu, which reads the
header to determine what kind of PDU arrived and decodes it as that type.
// open-dis-rust - Rust implementation of the IEEE 1278.1-2012 Distributed Interactive
// Simulation (DIS) application protocol
// Copyright (C) 2026 Cameron Howell
//
// Licensed under the BSD 2-Clause License
use std::{error::Error, net::UdpSocket};
use open_dis_rust::prelude::*;
fn main() -> Result<(), Box<dyn Error>> {
let socket = UdpSocket::bind("0.0.0.0:3000")?;
println!("listening on {}", socket.local_addr()?);
let mut buf = [0u8; MAX_PDU_SIZE_OCTETS];
loop {
let (n, from) = socket.recv_from(&mut buf)?;
let Some(mut datagram) = buf.get(..n) else {
continue;
};
// The header says which PDU it is, and AnyPdu decodes it as that type
match AnyPdu::deserialize(&mut datagram) {
Ok(AnyPdu::EntityState(pdu)) => println!(
"{from}: entity {}:{}:{} '{}' at ({:.1}, {:.1}, {:.1})",
pdu.entity_id.simulation_address.site_id,
pdu.entity_id.simulation_address.application_id,
pdu.entity_id.entity_id,
pdu.entity_marking.as_ascii().unwrap_or("?"),
pdu.entity_location.x_coordinate,
pdu.entity_location.y_coordinate,
pdu.entity_location.z_coordinate,
),
Ok(other) => println!("{from}: ignoring {:?} PDU", other.pdu_type()),
Err(e) => eprintln!("{from}: undecodable datagram: {e}"),
}
}
}
AnyPdu has one variant per PDU type, named after its PduType, so you match on the
ones you wish to explicitly handle. deserialize returns an error instead of panicking when
a datagram is truncated or malformed. A receiver on a shared network might expect to receive
some bad PDUs at times.
3. Run the examples
In one terminal, start the receiver:
cargo run --example quickstart_receive
In a second terminal, start the sender:
cargo run --example quickstart_send
The sender reports each PDU it sends:
sent 144-byte Entity State PDU, x = 6378137.0
sent 144-byte Entity State PDU, x = 6378147.0
sent 144-byte Entity State PDU, x = 6378157.0
The receiver prints the tank moving 10 meters along the x-axis each second:
listening on 0.0.0.0:3000
127.0.0.1:35774: entity 1:1:1 'TANK01' at (6378137.0, 0.0, 0.0)
127.0.0.1:35774: entity 1:1:1 'TANK01' at (6378147.0, 0.0, 0.0)
127.0.0.1:35774: entity 1:1:1 'TANK01' at (6378157.0, 0.0, 0.0)
NOTE: Source ports will differ as they are chosen at runtime.
4. Observe packets in Wireshark (optional)
Wireshark includes a dissector for the DIS protocol, which makes it the easiest way to check what your application is actually putting out on the wire.
How to use the DIS dissector:
- Start a capture on the loopback interface.
- Enter
disin the display filter bar. - Run the sender again.
Each packet should decode as an Entity State PDU, with the entity ID, entity type, marking, and location you set. If the dissector does not recognize the traffic, check that you are sending on the correct port (3000), or right-click a packet and choose Decode As… -> DIS.
Sending to other machines
The sender in this example talks only to 127.0.0.1. To reach other simulators on your network,
send to your subnet’s broadcast address or to a multicast group your exercise agrees on. For
broadcast, enable it on the socket first:
let socket = UdpSocket::bind("0.0.0.0:0")?;
socket.set_broadcast(true)?;
socket.connect("192.168.1.255:3000")?; // replace with your subnet's broadcast address
Every participant must also use the same exercise ID, which this example sets to 1. This
rule is not enforced by this crate, but it is specified in the DIS standard. Most DIS applications
ignore PDUs from other exercises.
Next steps
- Creating a PDU covers building other PDU types.
- Sending PDUs shows sending with
tokio. - Receiving PDUs covers receiving in more depth.