Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Future Mod Project] Use 'laminar' as Rust networking library. #57

Open
Sewer56 opened this issue Aug 31, 2024 · 0 comments
Open

[Future Mod Project] Use 'laminar' as Rust networking library. #57

Sewer56 opened this issue Aug 31, 2024 · 0 comments

Comments

@Sewer56
Copy link
Member

Sewer56 commented Aug 31, 2024

Needs some header size optimization, like here: https://github.com/TimonPost/laminar/blob/e8ffb26a915bb6ac3c8d959031d63f8a776e763c/src/packet/header/standard_header.rs#L88

But aside from that, is a-ok. For file transfer, and 32+ player games, we need path MTU discovery.

Otherwise, combine with igd for UPnP

use igd::{search_gateway, Gateway};
use std::net::Ipv4Addr;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Search for the gateway
    let gateway = search_gateway(Default::default())?;

    // The local address to map (usually your computer's local IP)
    let local_addr = Ipv4Addr::new(192, 168, 1, 100); // Replace with your actual local IP

    // The external port you want to open
    let external_port = 12345;

    // The internal port you want to map to (can be the same as external_port)
    let internal_port = 12345;

    // The protocol (TCP or UDP)
    let protocol = igd::PortMappingProtocol::TCP;

    // The lease duration in seconds (0 for indefinite)
    let lease_duration = 0;

    // The description for this port mapping
    let description = "My Rust Application";

    // Add the port mapping
    gateway.add_port(protocol, external_port, (local_addr, internal_port), lease_duration, description)?;

    println!("Port {} opened successfully", external_port);

    Ok(())
}

and with a port of MLAPI.Puncher to Rust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant