I want to create a rust tcp server with tokio that can support multiple clients at the same time and that has a list of all connect clients so I can broadcast messages to all of them, but tokio/examples/chat.rs at master · tokio-rs/tokio · GitHub
does not seem like the ideal solution as:
It requires a lot of different crates.
I can't get to run it.
It just seems weird.
Are there any better examples I could base myself on? Or should I just modify the example a lot?
It requires six crates, one being tokio itself. I believe you can get rid of the tokio_stream dependency by using futures::stream::StreamExt instead of tokio_stream::StreamExt. Plus you could remove tracing and tracing_subscriber to simplify or remove the logging and reduce that boilerplate, leaving you with futures, tokio and tokio_util, which I find a more than reasonable list of dependencies.
Do you have an error message you can share with us? That would possibly allow us to better help you get the example to run on your computer.
What exactly seems weird to you? I find it quite the reasonable example that does pretty much exactly what you are looking for according to my interpretation of your description:
Please be aware that the Rust std library does not have any async libraries built in. This is by design, to rely on the ecosystem to provide various types of async libraries. So you will always need to use some crates when using async, and this is not considered a drawback in Rust.
I successfully removed tracing and tracing_subscriber, and got it to run but it's just that the entire code looks weird but ig I'll divide it in different files and make it look a bit better and it'll be fine, ty for the help.