#Best crate for async network event handling?

1 messages · Page 1 of 1 (latest)

pliant juniper
#

Longtime network programmer here but new to Rust (I read The Book). As an exercise, I have an app server using Websockets written in NodeJS that I want to rewrite in Rust. For performance, I want to use async event handling instead of multithreading. This is simple in JavaScript/Node-- just use addEventHandler() or set e.g. onmessage. Is there anything similar available in Rust, to simply set handlers triggered by network events? I've looked a little at Tokio and async-std, but don't see anything obvious. I'm trying to avoid a complete rearchitecting of the server, but can do that if there's no other choice.

I welcome all other advice on how to approach this project too. Thanks for any tips! 😊

sweet iris
#

if you're going to use strictly websockets - i recommend tokio + tokio-tungstenite

#

if you want a webserver with websocket support, i believe axum has that covered too (with a feature flag iirc)

#

to be clear: tokio is an async runtime (just like async-std). Rust doesn't come with an async runtime built in, unlike nodejs

pliant juniper
#

Excellent, thanks! I'll check out tokio-tungstenite. Yes, my ap uses a custom protocol that only uses Websockets, no HTTP beyond the handshake.

sweet iris
sweet iris
rough pantherBOT
#

Tokio binding for Tungstenite, the Lightweight stream-based WebSocket implementation

Version

0.21.0

Downloads

29 010 521

pliant juniper
#

Right (about async runtimes).

#

Very cool, thank you so much! This looks like what I need.

sweet iris
#

their repository has quite a few examples to get you started

pliant juniper
#

Great!

sweet iris
#

also, i highly recommend using something like futures_util alongside tungstenite, it is also used in their examples.

#

good luck

pliant juniper
#

That sounds good too, I'll check it out.

#

Thanks for the help. 😊

sweet iris
#

np