broadcast_pdus/
broadcast_pdus.rs1use std::{net::UdpSocket};
10
11use bytes::BytesMut;
12
13extern crate dis_rust;
14use dis_rust::{warfare::{fire_pdu::FirePDU, detonation_pdu::DetonationPDU}, entity_information::entity_state_pdu::EntityStatePDU, simulation_management::event_report_pdu::EventReportPDU, common::pdu::PDU};
15
16const SRC_PORT: u16 = 3000;
17
18fn main() {
19 let src_addr = format!("192.168.1.134:{}", SRC_PORT);
20 println!("binding to {} for sending", src_addr.as_str());
21 let socket = UdpSocket::bind(src_addr).expect("bind should succeed");
22
23 socket.set_broadcast(true).expect("set_broadcast to true should succeed");
24
25 let data_to_send = FirePDU::default();
27 println!("broadcasting data: {:?}", data_to_send);
28 let mut buffer = BytesMut::new();
29 PDU::serialise(&data_to_send, &mut buffer);
30 socket
31 .send_to(&buffer, format!("255.255.255.255:{}", SRC_PORT))
32 .expect("couldn't send data");
33
34 let data_to_send = EventReportPDU::default();
36 println!("broadcasting data: {:?}", data_to_send);
37 let mut buffer = BytesMut::new();
38 PDU::serialise(&data_to_send, &mut buffer);
39 socket
40 .send_to(&buffer, format!("255.255.255.255:{}", SRC_PORT))
41 .expect("couldn't send data");
42
43
44 let data_to_send = EntityStatePDU::default();
46 println!("broadcasting data: {:?}", data_to_send);
47 let mut buffer = BytesMut::new();
48 PDU::serialise(&data_to_send, &mut buffer);
49 socket
50 .send_to(&buffer, format!("255.255.255.255:{}", SRC_PORT))
51 .expect("couldn't send data");
52
53 let data_to_send = DetonationPDU::default();
55 println!("broadcasting data: {:?}", data_to_send);
56 let mut buffer = BytesMut::new();
57 PDU::serialise(&data_to_send, &mut buffer);
58 socket
59 .send_to(&buffer, format!("255.255.255.255:{}", SRC_PORT))
60 .expect("couldn't send data");
61}