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

Closing connection #259

Open
colinbes opened this issue Apr 18, 2021 · 3 comments
Open

Closing connection #259

colinbes opened this issue Apr 18, 2021 · 3 comments

Comments

@colinbes
Copy link

I am using crate to connect ws client to a device server using socket.io which is able to switch to websockets. I am connecting to device using url ws://ipaddress/socket.io/?EIO=3&transport=websocket.

This connects fine and I am getting messages from the device but after about 80 seconds it receives a Close notification which I am unable to track down. If I connect via browser to device and connect using socket.io library the connection stays alive. In browser code (using socket.io) I am not specifically sending and packets to the device so am not sure if I am getting Close message due to me not sending any data to the device (device with socket server) or whether Close is generated on websocket Client side due to too infrequent messages (server sends message roughly every 20 seconds).

Should I be sending periodic messages to the server? Or is it due to infrequent messages from server (I don't think it is this).

Appreciate any feedback ideas - busy digging into info....

@vi
Copy link
Member

vi commented Apr 18, 2021

You can debug unencrypted (ws://) WebSocket messages using network investigation tool like Wireshark. You should see whether there is a message with opcode: Connection close (8).

@colinbes
Copy link
Author

I know I am getting close message with status code of 1000. I don't know why I am getting it though.

@colinbes
Copy link
Author

As a quick hack, I added simple doTick function to periodically send short text message to server - now I don't get the close message and my connection stays connected.

Now looking for best way to do this - I don't see way to do this via websocket crate settings - am I missing something, can this be handled by websocket crate or should I implement this myself?

Battling a bit with my newness to Rust on best way to accomplish this.

	async fn do_tick(sender: &mut Writer<TcpStream>) {
		let mut interval = time::interval(Duration::from_secs(10));
		loop {
			interval.tick().await;
			println!("tick");
			let _ = sender.send_message(&OwnedMessage::Text(String::from("2"))).unwrap();
		}
	}
	
	let _ = do_tick(&mut sender).await;

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

2 participants