multicast

This commit is contained in:
0m.ax 2025-07-20 15:57:55 +02:00
parent 6c65b78e6c
commit fa4cfcd7b8
3 changed files with 41 additions and 1 deletions

33
Cargo.lock generated
View file

@ -73,6 +73,7 @@ dependencies = [
"libc", "libc",
"nix", "nix",
"png", "png",
"socket2",
] ]
[[package]] [[package]]
@ -131,3 +132,35 @@ name = "simd-adler32"
version = "0.3.7" version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]]
name = "socket2"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -7,3 +7,4 @@ edition = "2024"
png = "0.17" png = "0.17"
libc = "0.2" libc = "0.2"
nix = { version = "0.29", features = ["socket", "uio"] } nix = { version = "0.29", features = ["socket", "uio"] }
socket2 = "0.4.7"

View file

@ -4,6 +4,8 @@ use std::net::{ToSocketAddrs, UdpSocket};
use std::time::Duration; use std::time::Duration;
use std::thread; use std::thread;
use std::sync::{Mutex,Arc}; use std::sync::{Mutex,Arc};
use socket2::{Domain, Socket, Type};
use std::net::{Ipv4Addr, SocketAddr};
mod color; mod color;
// Constants from the C code // Constants from the C code
const QUEUE_LEN: usize = 1000; const QUEUE_LEN: usize = 1000;
@ -323,7 +325,11 @@ fn main() {
let mut frame_counter: u32 = 0; let mut frame_counter: u32 = 0;
thread::spawn(move || { thread::spawn(move || {
let bind_address = format!("0.0.0.0:12345"); let bind_address = format!("0.0.0.0:12345");
let socket = Socket::new(Domain::IPV4, Type::DGRAM, None).unwrap();
socket.set_reuse_address(true).unwrap();
socket.set_nonblocking(true).unwrap();
socket.join_multicast_v4(&Ipv4Addr::new(239, 1, 1, 1), &Ipv4Addr::new(0, 0, 0, 0)).unwrap();
socket.bind(&"0.0.0.0:12345".parse::<SocketAddr>().unwrap().into()).unwrap();
// Bind the UDP socket to the specified address and port. // Bind the UDP socket to the specified address and port.
let socket = match UdpSocket::bind(&bind_address) { let socket = match UdpSocket::bind(&bind_address) {
Ok(s) => s, Ok(s) => s,