RedpointArchive / netcode.io-browser

Browser extensions which enable the use of netcode.io (secure UDP) prior to adoption in web browsers
293 stars 22 forks source link

unexisting client id #10

Open paaaav opened 5 years ago

paaaav commented 5 years ago

Hello!

I'm using a modified version of the unsupported Rust port, but maybe this does not matter. I successfully connected a server application to a separate client application (both in Rust) with netcode 1.01, they exchange information very well. It does not work for me using a browser, that connects to the very same server. Curiously the official test page https://netcode.redpoint.games/basic works.

What am I missing here? I installed the browser extension for Firefox and Chromium, my local test page delivers the error "unexisting client id xxxx", where xxxx varies, when connecting locally to my server.

Example:

This page tests netcode.io support in your browser.

Status of window.netcode: Available!

Status of netcode client: Error: unexisting client id: 443299215

Status of netcode connection: sendingConnectionResponse

Packets sent to server: ...

Last packet received from server: ..."

While the server has the following lines in the log:

TRACE: New data on listening socket
TRACE: Sending challenge packet
TRACE: Accepted connection V4(127.0.0.1:28356)

(nothing happens, I press f5 on the test page)

TRACE: New data on listening socket
TRACE: Client already exists, skipping socket creation
TRACE: Sending challenge packet
TRACE: Failed to hear from client 11184811, timed out
TRACE: Client disconnected 11184811
Server: ClientDisconnect '11184811'
TRACE: New data on listening socket
TRACE: Sending challenge packet
TRACE: Accepted connection V4(127.0.0.1:30939)

I tracked this error a while and it seems to come from the browser extension. The reason is that the server does not seem to receive the event ServerEvent::ClientConnect when I'm using the browser extension. Thus the client id is unexisting, but the connection seems to be established " Accepted connection V4(127.0.0.1:30939)".

What can be the cause that the server does not receive ClientConnect?

hach-que commented 5 years ago

So the incompatibility only occurs when you use the browser (Go client) with your Rust server? But Rust client -> Rust server and Browser (Go) client -> C# server both work fine?

Can you try connecting a Rust client to a C# server directly? And can you set this up somewhere publicly so I can replicate the issue?

paaaav commented 5 years ago

Yes, you got it! This is what I observe. But maybe this is only a problem on my end.

I'll test this further. It will take me some time. Thanks!

paaaav commented 5 years ago

Thanks for your support. You're totally right. The C# implementation works fine. I compiled the C# test server application in Linux, extracted the token and fed it to the browser demo page I have locally. It works. C# client to C# server also no problem here.

Can you try connecting a Rust client to a C# server directly?

Will do (later)!

I tested the following three rust netcode repos:

netcode = {git = "https://github.com/Game-Insight/netcode.io"}
netcode = {git = "https://github.com/vvanders/netcode.io"} (is netcode 1.00, does not work anymore)
netcode = "*" (is netcode 1.00, does not work anymore)

On a side-note, It's sad no one is maintaining the rust ports anymore, especially since the published netcode crate (https://crates.io/crates/netcode) is 1.00 which won't work with the current browser extension.

How to reproduce:

toml

[package]
name = "server"
version = "0.1.0"

[dependencies]
netcode = {git = "https://github.com/Game-Insight/netcode.io"}
base64= "*"
time = "*"
env_logger = "*"
log = "*"

main.rs

extern crate base64;
extern crate time;
extern crate netcode;
extern crate env_logger;
extern crate log;

use netcode::{NETCODE_MAX_PAYLOAD_SIZE, ServerEvent, UdpServer};
use std::thread;
use env_logger::Builder;
use log::{LevelFilter};
use std::time::Duration;

const CLIENT_ID: u64 = 0xAAAAAB; 

fn main()
{

    let mut builder = Builder::new();
    builder.filter(None, LevelFilter::Trace);
    builder.init();

    //let private_key = netcode::generate_key();
    //let token_base64 = base64::encode(&private_key);
    //println!("{}",token_base64);

    let s_key = base64::decode("lczX6AyqZVaQGo0t+RrrKW5TxVv8xMGBBKS/7pf8Lc0=").expect("pkey");

    let mut private_key: [u8; 32] = Default::default();
    private_key.copy_from_slice(&s_key[..]);

    const PROTOCOL_ID: u64 = 2;
    const TOKEN_LIFETIME: usize = 600000;
    let mut server = UdpServer::new("127.0.0.1:8040", 1000usize, PROTOCOL_ID, &private_key).unwrap();

    let token = server.generate_token(TOKEN_LIFETIME, CLIENT_ID, None).unwrap();
    let mut token_bytes = Vec::new();
    token.write(&mut token_bytes).unwrap();
    let token_base64 = base64::encode(&token_bytes);
    println!("Server Token:\n\n{}\n\n", token_base64);

    let server_thread = thread::spawn(move || {
        let mut last = 0.0;

        loop {
            let elapsed = sleep_for_tick(&mut last);
            server.update(elapsed);

            let mut packet = [0; NETCODE_MAX_PAYLOAD_SIZE];
            while let Some(event) = server.next_event(&mut packet).unwrap() {
                match event {
                    ServerEvent::ClientConnect(id) => {
                        println!("Server: client connected '{}'", id);
                    }
                    ServerEvent::ClientDisconnect(id) => {
                        println!("Server: ClientDisconnect '{}'", id);
                    }
                    ServerEvent::Packet(id, size) => {
                        println!("Server: send back to '{}'", id);
                        server.send(id, &packet[..size]).unwrap();
                    }
                    ServerEvent::SentKeepAlive(id) => { println!("Server: SentKeepAlive id {}",id); }
                    ServerEvent::RejectedClient => { println!("Server: RejectedClient"); }
                    ServerEvent::ReplayRejected(id) => { println!("Server: ReplayRejected id {}",id); }
                    ServerEvent::ClientSlotFull => { println!("Server: ClientSlotFull"); }
                }
            }
        }
    });
    server_thread.join().unwrap();
}

const TICK_TIME_MS: f64 = 0.008;

//Helper function for sleeping at a regular interval
fn sleep_for_tick(last_tick: &mut f64) -> f64 {
    let now = time::precise_time_s();

    let elapsed = (now - *last_tick).min(TICK_TIME_MS);

    if elapsed < TICK_TIME_MS {
        let sleep_ms = ((TICK_TIME_MS - elapsed) * 1000.0).floor() as u64;
        thread::sleep(Duration::from_millis(sleep_ms));
    }

    *last_tick = now;
    TICK_TIME_MS
}

I'm getting the "unexisting client id" when feeding the token to the browser extension demo page.

gafferongames commented 5 years ago

The difference between 1.0 and 1.1 is verrrry small. Best way forward would be to just fork a Rust implementation and update it.

I'm sorry I just don't have the time to do this myself, and there is something about Rust syntax that makes my brain recoil in horror... so it's not something I'm comfortable in doing myself.

cheers

On Sun, Sep 2, 2018 at 9:54 AM, paaaav notifications@github.com wrote:

Thanks for your support. You're totally right. The C# implementation works fine. I compiled the C# test application in Linux, extracted the token and fed it to the browser demo page I have locally. It works. C# client to C# server also no problem here.

Can you try connecting a Rust client to a C# server directly?

Will do (later)!

I tested the following three rust netcode repos:

netcode = {git = "https://github.com/Game-Insight/netcode.io"} netcode = {git = "https://github.com/vvanders/netcode.io"} (is netcode 1.00, does not work anymore) netcode = "*" (is netcode 1.00, does not work anymore)

On a side-note, It's sad no one is maintaining the rust ports anymore, especially since the published netcode crate (https://crates.io/crates/ netcode) is 1.00 which won't work with the current browser extension.

How to reproduce:

toml

[package] name = "server" version = "0.1.0"

[dependencies] netcode = {git = "https://github.com/Game-Insight/netcode.io"} base64= "" time = "" env_logger = "" log = ""

main.rs

extern crate base64; extern crate time; extern crate netcode; extern crate env_logger; extern crate log;

use netcode::{NETCODE_MAX_PAYLOAD_SIZE, ServerEvent, UdpServer}; use std::thread; use env_logger::Builder; use log::{LevelFilter}; use std::time::Duration;

const CLIENT_ID: u64 = 0xAAAAAB;

fn main() {

let mut builder = Builder::new(); builder.filter(None, LevelFilter::Trace); builder.init();

//let private_key = netcode::generate_key(); //let token_base64 = base64::encode(&private_key); //println!("{}",token_base64);

let s_key = base64::decode("lczX6AyqZVaQGo0t+RrrKW5TxVv8xMGBBKS/7pf8Lc0=").expect("pkey");

let mut private_key: [u8; 32] = Default::default(); private_key.copy_from_slice(&s_key[..]);

const PROTOCOL_ID: u64 = 2; const TOKEN_LIFETIME: usize = 600000; let mut server = UdpServer::new("127.0.0.1:8040", 1000usize, PROTOCOL_ID, &private_key).unwrap();

let token = server.generate_token(TOKEN_LIFETIME, CLIENT_ID, None).unwrap(); let mut token_bytes = Vec::new(); token.write(&mut token_bytes).unwrap(); let token_base64 = base64::encode(&token_bytes); println!("Server Token:\n\n{}\n\n", token_base64);

let server_thread = thread::spawn(move || { let mut last = 0.0;

  loop {
      let elapsed = sleep_for_tick(&mut last);
      server.update(elapsed);

      let mut packet = [0; NETCODE_MAX_PAYLOAD_SIZE];
      while let Some(event) = server.next_event(&mut packet).unwrap() {
          match event {
              ServerEvent::ClientConnect(id) => {
                  println!("Server: client connected '{}'", id);
              }
              ServerEvent::ClientDisconnect(id) => {
                  println!("Server: ClientDisconnect '{}'", id);
              }
              ServerEvent::Packet(id, size) => {
                  println!("Server: send back to '{}'", id);
                  server.send(id, &packet[..size]).unwrap();
              }
              ServerEvent::SentKeepAlive(id) => { println!("Server: SentKeepAlive id {}",id); }
              ServerEvent::RejectedClient => { println!("Server: RejectedClient"); }
              ServerEvent::ReplayRejected(id) => { println!("Server: ReplayRejected id {}",id); }
              ServerEvent::ClientSlotFull => { println!("Server: ClientSlotFull"); }
          }
      }
  }

}); server_thread.join().unwrap(); }

const TICK_TIME_MS: f64 = 0.008;

//Helper function for sleeping at a regular interval fn sleep_for_tick(last_tick: &mut f64) -> f64 { let now = time::precise_time_s();

let elapsed = (now - *last_tick).min(TICK_TIME_MS);

if elapsed < TICK_TIME_MS { let sleep_ms = ((TICK_TIME_MS - elapsed) * 1000.0).floor() as u64; thread::sleep(Duration::from_millis(sleep_ms)); }

*last_tick = now; TICK_TIME_MS }

I'm getting the "unexisting client id" when feeding the token to the browser extension demo page.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/RedpointGames/netcode.io-browser/issues/10#issuecomment-417944082, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqhUBVzVSXYErFYQkGtoNIDMrP0xUx1ks5uXA1agaJpZM4WELL5 .