Comments (5)
1. Is my workaround just a hack? Is it best practice to broadcast the close message so other clients know one client has closed?
I think that's the correct way of doing it, yes. Broadcasting the normal close message will close the connection for everybody, which is usually not what you want.
2\. Should the example be updated?
I think that was be useful, thanks :)
from async-tungstenite.
I guess this can be closed now? :) If not tell me and I'll reopen.
from async-tungstenite.
Hmm, this is actually interesting though. If I run your server-client example, I don't see this behavior (where closing one client closes the rest of the clients). I'm not sure if this is specific to when the client is a JS websocket client or something? I'm interested in your intuition on this:
- I started the server:
cargo run --features="async-std-runtime" --example server 127.0.0.1:12345
- I started a rust client:
cargo run --features="async-std-runtime" --example client ws://127.0.0.1:12345/
- I added an
index.html
file toexamples
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<script>
document.addEventListener('DOMContentLoaded', function() {
const ws = new WebSocket('ws://127.0.0.1:12345');
ws.addEventListener('open', function() {
ws.addEventListener('message', function({ data }) {
console.log(data)
})
ws.addEventListener('close', function() {
console.log('closed')
})
})
})
</script>
</body>
</html>
- I opened
index.html
in two windows - one in FF, one in chrome just be safe. - I typed into the rust client and saw a blob logged in the console of both windows to ensure the broadcast was working.
- Now, if I close either browser tab, it closed the other browser tab and the rust command-line client.
But if I connect with two rust clients and close one, the other client doesn't close. Also if I connect with one rust client and one JS client and then close the rust client, the JS client isn't closed. Do you think this is a JS bug or something instead of an issue with broadcasting the close message?
Tangentially I noticed that if you try running the command listed at the top of the example, you get an error:
error: target `client` in package `async-tungstenite` requires the features: `async-std-runtime`
Consider enabling them by passing, e.g., `--features="async-std-runtime"`
Do you want me to update the commands in the example or should we leave it as to keep the commands shorter because the error is so well written?
from async-tungstenite.
Hmm, this is actually interesting though. If I run your server-client example, I don't see this behavior (where closing one client closes the rest of the clients). I'm not sure if this is specific to when the client is a JS websocket client or something? I'm interested in your intuition on this:
Maybe no Close
message is sent in that case but the underlying TCP connection is just closed? If you just quit the Rust application it will simply stop and not have the opportunity to cleanly close the websocket connection (i.e. sending the Close
message). And because of that, this message also wouldn't be broadcasted. Sending the Close
message is optional and you'd have to do that explicitly in the Rust code.
Are you saying your code is not behaving the same as the examples, can you share your code in that case? :)
Do you want me to update the commands in the example or should we leave it as to keep the commands shorter because the error is so well written?
Updating those would be a good idea, thanks :)
from async-tungstenite.
If you just quit the Rust application it will simply stop and not have the opportunity to cleanly close the websocket connection
Ah! That could very well be it. Great, I'll go ahead with those updates then.
from async-tungstenite.
Related Issues (20)
- Inspecting the steam buffer HOT 3
- "thread 'async-std/runtime' panicked" when running "echo-server" example HOT 1
- Support fragmented messages HOT 3
- How to close connection gracefully after WebSocketStream.split()? HOT 2
- [Question]: How to optimise the memory usage for websocket client HOT 5
- could not find `async_std` in `async_tungstenite` HOT 6
- Support for the `smol` runtime HOT 1
- Add vendored feature for dependency crates so that statically linked OpenSSL can be used HOT 1
- ResetWithoutClosingHandshake when server sends more frequent messages. HOT 1
- Can't find `tungstenite::client::IntoClientRequest` HOT 5
- how to close websocket after it has been moved into select? HOT 12
- Task wakes too often in release mode when used with `async_std` HOT 11
- max connect just 50 onely HOT 2
- How to add TLS support to a websocket server for wss to work? HOT 2
- Disable certificate validation HOT 2
- How to disable logging for compact? HOT 5
- Avoid webpki-roots as a default dependency when tokio-rustls is used HOT 5
- Is it possible to flush all buffered messages before closing the stream? HOT 5
- Cloning `WebSocketStream`s HOT 1
- Initial report: stack overflow on windows with 0.15 HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-tungstenite.