1
0
mirror of https://github.com/actix/examples synced 2025-06-28 18:00:37 +02:00

upgrade example to actix-web 0.7

This commit is contained in:
Nikolay Kim
2018-07-16 12:36:53 +06:00
parent 0b52c7850e
commit 2cc1b23761
57 changed files with 913 additions and 693 deletions

View File

@ -5,13 +5,11 @@ extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate futures;
extern crate tokio_core;
use std::time::Duration;
use std::{io, thread};
use actix::*;
use actix_web::ws::WsWriter;
use actix_web::ws::{Client, ClientWriter, Message, ProtocolError};
use futures::Future;
@ -20,7 +18,7 @@ fn main() {
let _ = env_logger::init();
let sys = actix::System::new("ws-example");
Arbiter::handle().spawn(
Arbiter::spawn(
Client::new("http://127.0.0.1:8080/ws/")
.connect()
.map_err(|e| {
@ -28,7 +26,7 @@ fn main() {
()
})
.map(|(reader, writer)| {
let addr: Addr<Syn, _> = ChatClient::create(|ctx| {
let addr = ChatClient::create(|ctx| {
ChatClient::add_stream(reader, ctx);
ChatClient(writer)
});
@ -67,7 +65,7 @@ impl Actor for ChatClient {
println!("Disconnected");
// Stop application on disconnect
Arbiter::system().do_send(actix::msgs::SystemExit(0));
System::current().stop();
}
}

View File

@ -14,7 +14,7 @@ use actix_web::{
};
/// do websocket handshake and start `MyWebSocket` actor
fn ws_index(r: HttpRequest) -> Result<HttpResponse, Error> {
fn ws_index(r: &HttpRequest) -> Result<HttpResponse, Error> {
ws::start(r, MyWebSocket)
}
@ -56,6 +56,7 @@ fn main() {
.resource("/ws/", |r| r.method(http::Method::GET).f(ws_index))
// static files
.handler("/", fs::StaticFiles::new("static/")
.unwrap()
.index_file("index.html")))
// start http server on 127.0.0.1:8080
.bind("127.0.0.1:8080").unwrap()