Search code examples
rustwarp

How to listen on multiple ports with warp?


warp::serve(routes)
    .run(([127, 0, 0, 1], 3030))
    .await;

How can I listen to different ports for http requests and websocket connection?


Solution

  • You can start two separate instances and run them concurrently:

    tokio::join!(
        warp::serve(routes).run(([127, 0, 0, 1], 3030)),
        warp::serve(routes).run(([127, 0, 0, 1], 3031)),
    );
    

    Inspired by Run multiple actix app on different ports