-
Notifications
You must be signed in to change notification settings - Fork 42
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
how to have websocket, http2/3, router on the same script? #983
Comments
@fakeshadow stuck here, how to do wt with /wt together on :443?
|
[dependencies]
xitca-http = { version = "0.4", features = ["http2", "http3", "rustls"] }
xitca-server = { version = "0.2", features = ["http3"] }
xitca-web = { version = "0.4", features = ["websocket"] }
quinn = "0.10"
rustls = "0.23"
use std::sync::Arc;
use xitca_http::HttpServiceBuilder;
use xitca_web::{
handler::{
handler_service,
websocket::{Message, WebSocket},
},
route::get,
service::ServiceExt,
App,
};
fn main() -> std::io::Result<()> {
let service = App::new()
.at("/", get(handler_service(handler)))
.finish()
.enclosed(HttpServiceBuilder::new().rustls(rustls_config()));
xitca_server::Builder::new()
.bind_all("xitca-web", "localhost:8080", quinn_config(), service)?
.build()
.wait()
}
async fn handler(mut ws: WebSocket) -> WebSocket {
ws.on_msg(|tx, msg| {
Box::pin(async move {
if let Message::Text(txt) = msg {
println!("Got text message: {txt}");
tx.text(format!("Echo: {txt}")).await.unwrap();
}
})
});
ws
}
fn rustls_config() -> Arc<rustls::ServerConfig> {
// your rustls config goes here
todo!()
}
fn quinn_config() -> quinn::ServerConfig {
// your quinn config goes here
todo!()
} If you take a closer look at the previous issue you would know the answer is already there for you. This crate is not a hand held coding session. |
The most fatal mistake is like I previously pointed out. You are using an example that show casing handling multiple http services as your template for everything. The example is not for your use case and you should look else where (And I pointed it out in previous issue you just don't want to follow it) |
@fakeshadow you are right in everything. i'm just newbie rustlang learner. i really like xitca performance etc but it's really difficult to use. please take a look at : hope you can do something along this line in future. I think I have to go with salvo coz the learning curve is too steep for me at this stage for xitca. I've been trying hard to make it happen for the past 2 days and hope you can go along the lines of salvo so in future will port my code back to xitca for the performance. thanks a lot. xitca is great but i'm just too dense to use it for the moment. sorry to trouble you so much but will definitely support this project. |
needed the performance, back to using xitca. can you help out this part and add to your example? cant get this part to work. pls help do a routing where /ws is websocket and /plaintext is hello world.
|
is it possible for you to show a working example of :
websocket, http2/3 and router on the same script?
after 1 whole day doing rust, this is all i have, i have no idea how to add websocket to /ws and how to do recommended "routing".
i also dunno how to do static file like the m/a.css routing
pls help. thx:
The text was updated successfully, but these errors were encountered: