Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

unexisting client id #10

Open
paaaav opened this issue Aug 20, 2018 · 4 comments
Open

unexisting client id #10

paaaav opened this issue Aug 20, 2018 · 4 comments

Comments

@paaaav
Copy link

paaaav commented Aug 20, 2018

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
Copy link
Contributor

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
Copy link
Author

paaaav commented Aug 21, 2018

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
Copy link
Author

paaaav commented Sep 2, 2018

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
Copy link
Contributor

gafferongames commented Sep 2, 2018 via email

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

No branches or pull requests

3 participants