mirror of
https://github.com/actix/examples
synced 2025-06-26 17:17:42 +02:00
update all websocket examples to v4
This commit is contained in:
@ -8,7 +8,9 @@ name = "websocket-autobahn-server"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
actix = "0.10"
|
||||
actix-web = "3"
|
||||
actix-web-actors = "3"
|
||||
env_logger = "0.8"
|
||||
actix = "0.12"
|
||||
actix-web = "4.0.0-rc.3"
|
||||
actix-web-actors = "4.0.0-beta.12"
|
||||
|
||||
env_logger = "0.9"
|
||||
log = "0.4"
|
||||
|
@ -1,22 +1,21 @@
|
||||
# websocket
|
||||
# WebSocket Autobahn Test Server
|
||||
|
||||
Websocket server for autobahn suite testing.
|
||||
WebSocket server for the [Autobahn WebSocket protocol testsuite](https://github.com/crossbario/autobahn-testsuite).
|
||||
|
||||
## Usage
|
||||
|
||||
### server
|
||||
### Server
|
||||
|
||||
```bash
|
||||
cd websockets/autobahn
|
||||
cargo run --bin websocket-autobahn-server
|
||||
cargo run
|
||||
```
|
||||
|
||||
### Running Autobahn Test Suite
|
||||
|
||||
Running the autobahn test suite is easiest using the docker image
|
||||
as explained on the [autobahn-testsuite repo](https://github.com/crossbario/autobahn-testsuite#using-the-testsuite-docker-image).
|
||||
Running the autobahn test suite is easiest using the docker image as explained on the [autobahn test suite repo](https://github.com/crossbario/autobahn-testsuite#using-the-testsuite-docker-image).
|
||||
|
||||
First, start a server (see above). Then, run the test suite in fuzzingclient mode:
|
||||
After starting the server, in the same directory, run the test suite in "fuzzing client" mode:
|
||||
|
||||
```bash
|
||||
docker run -it --rm \
|
||||
|
@ -8,6 +8,7 @@
|
||||
],
|
||||
"cases": ["*"],
|
||||
"exclude-cases": [
|
||||
"9.*",
|
||||
"12.*",
|
||||
"13.*"
|
||||
],
|
||||
|
@ -3,18 +3,17 @@ use actix_web::{middleware, web, App, Error, HttpRequest, HttpResponse, HttpServ
|
||||
use actix_web_actors::ws;
|
||||
|
||||
async fn ws_index(r: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
|
||||
ws::start(WebSocket::new(), &r, stream)
|
||||
ws::start(AutobahnWebSocket::default(), &r, stream)
|
||||
}
|
||||
|
||||
struct WebSocket {}
|
||||
#[derive(Debug, Clone, Default)]
|
||||
struct AutobahnWebSocket;
|
||||
|
||||
impl Actor for WebSocket {
|
||||
impl Actor for AutobahnWebSocket {
|
||||
type Context = ws::WebsocketContext<Self>;
|
||||
|
||||
fn started(&mut self, _ctx: &mut Self::Context) {}
|
||||
}
|
||||
|
||||
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WebSocket {
|
||||
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for AutobahnWebSocket {
|
||||
fn handle(
|
||||
&mut self,
|
||||
msg: Result<ws::Message, ws::ProtocolError>,
|
||||
@ -37,23 +36,19 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WebSocket {
|
||||
}
|
||||
}
|
||||
|
||||
impl WebSocket {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
|
||||
env_logger::init();
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
log::info!("starting HTTP server at http://localhost:9001");
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(middleware::Logger::default())
|
||||
.service(web::resource("/").route(web::get().to(ws_index)))
|
||||
})
|
||||
.bind("127.0.0.1:9001")?
|
||||
.workers(2)
|
||||
.bind(("127.0.0.1", 9001))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user