Created
February 14, 2020 03:48
-
-
Save azriel91/384b6fe230ceb219e52b7f106cd3a157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Listen to UDP packets through port 1234 | |
sudo tcpdump -i lo -n udp port 1234 | |
# UDP "server" | |
nc -lu 127.0.0.1 1234 | |
# UDP "client" | |
nc -u 127.0.0.1 1234 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adding relevant systems: | |
game_data = game_data | |
.with_bundle(LaminarNetworkBundle::new(local_socket()))? | |
.with_system_desc( | |
SessionJoinRequestSystemDesc::default(), | |
any::type_name::<SessionJoinRequestSystem>(), | |
&[any::type_name::<SharedControllerInputUpdateSystem>()], | |
) | |
fn local_socket() -> Option<LaminarSocket> { | |
let local_socket_config = LaminarConfig { | |
blocking_mode: false, | |
..Default::default() | |
}; | |
let local_socket = LaminarSocket::bind_any_with_config(local_socket_config); | |
match local_socket { | |
Ok(local_socket) => Some(local_socket), | |
Err(e) => { | |
warn!("Unable to bind to local socket. Network play will be unavailable."); | |
debug!("Local socket bind error: {}", e); | |
None | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from nc server | |
16:32:59.497639 IP 127.0.0.1.57095 > 127.0.0.1.1234: UDP, length 1 | |
# from nc client | |
16:32:59.653171 IP 127.0.0.1.57095 > 127.0.0.1.1234: UDP, length 1 | |
# from game | |
# [crate/network_join_play/src/system/session_join_request_system.rs:84] | |
# &message = "Request to join `abcd` from `azriel`" | |
16:33:00.965830 IP 127.0.0.1.49232 > 127.0.0.1.1234: UDP, length 52 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// === System that sends messages === // | |
let server_socket_addr = | |
SocketAddr::new(session_server_config.address, session_server_config.port); | |
let message = format!( | |
"Request to join `{}` from `{}`", | |
&session_join_request_params.session_code, | |
&session_join_request_params.session_device_name | |
); | |
// Connect to `server_socket_addr` and send request. | |
dbg!(&message); | |
transport_resource.send_with_requirements( | |
server_socket_addr, | |
message.as_bytes(), | |
// None means it uses a default multiplexed stream. | |
// | |
// Suspect if we give it a value, the value will be a "channel" over the same | |
// socket connection. | |
DeliveryRequirement::ReliableOrdered(None), | |
UrgencyRequirement::OnTick, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment