Skip to content

Commit

Permalink
feat: ✨ change boardcast address
Browse files Browse the repository at this point in the history
  • Loading branch information
yixiaojiu committed Nov 17, 2024
1 parent d369af6 commit 182ce10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kimika/src/request/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio::time;

pub async fn broadcast(mut close_rx: oneshot::Receiver<()>) -> Result<(), std::io::Error> {
let socket = UdpSocket::bind("0.0.0.0:0").await?;
let broadcast_addr: SocketAddr = ([255, 255, 255, 255], CONFIG.sender.receiver_port).into();
let broadcast_addr: SocketAddr = ([224, 0, 0, 139], CONFIG.sender.receiver_port).into();
socket.set_broadcast(true)?;

loop {
Expand Down
6 changes: 4 additions & 2 deletions kimika/src/server/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::request::local as request_local;
use crate::CONFIG;

use serde::{Deserialize, Serialize};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::net::SocketAddr;
use tokio::net::UdpSocket;
use tokio::sync::oneshot;

Expand All @@ -15,9 +15,11 @@ pub struct UDPPacket {
}

pub async fn listen_boardcast(mut close_rx: oneshot::Receiver<()>) -> Result<(), std::io::Error> {
let address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), CONFIG.receiver.port);
let address: SocketAddr = ([0, 0, 0, 0], CONFIG.sender.receiver_port).into();
let socket = UdpSocket::bind(address).await?;
socket.set_broadcast(true)?;

socket.join_multicast_v4("224.0.0.139".parse().unwrap(), "0.0.0.0".parse().unwrap())?;
let mut buffer = vec![0u8; BUFFER_SIZE];

loop {
Expand Down

0 comments on commit 182ce10

Please sign in to comment.