mirror of
https://github.com/actix/examples
synced 2025-06-28 09:50:36 +02:00
upgrade actix-web to 0.6
This commit is contained in:
@ -17,4 +17,4 @@ env_logger = "*"
|
||||
futures = "0.1"
|
||||
tokio-core = "0.1"
|
||||
actix = "0.5"
|
||||
actix-web = "^0.5"
|
||||
actix-web = "^0.6"
|
||||
|
@ -7,13 +7,13 @@ extern crate env_logger;
|
||||
extern crate futures;
|
||||
extern crate tokio_core;
|
||||
|
||||
use std::{io, thread};
|
||||
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;
|
||||
use actix_web::ws::{Message, ProtocolError, Client, ClientWriter};
|
||||
|
||||
|
||||
fn main() {
|
||||
::std::env::set_var("RUST_LOG", "actix_web=info");
|
||||
@ -34,25 +34,22 @@ fn main() {
|
||||
});
|
||||
|
||||
// start console loop
|
||||
thread::spawn(move|| {
|
||||
loop {
|
||||
let mut cmd = String::new();
|
||||
if io::stdin().read_line(&mut cmd).is_err() {
|
||||
println!("error");
|
||||
return
|
||||
}
|
||||
addr.do_send(ClientCommand(cmd));
|
||||
thread::spawn(move || loop {
|
||||
let mut cmd = String::new();
|
||||
if io::stdin().read_line(&mut cmd).is_err() {
|
||||
println!("error");
|
||||
return;
|
||||
}
|
||||
addr.do_send(ClientCommand(cmd));
|
||||
});
|
||||
|
||||
()
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
let _ = sys.run();
|
||||
}
|
||||
|
||||
|
||||
struct ChatClient(ClientWriter);
|
||||
|
||||
#[derive(Message)]
|
||||
@ -94,11 +91,10 @@ impl Handler<ClientCommand> for ChatClient {
|
||||
|
||||
/// Handle server websocket messages
|
||||
impl StreamHandler<Message, ProtocolError> for ChatClient {
|
||||
|
||||
fn handle(&mut self, msg: Message, ctx: &mut Context<Self>) {
|
||||
match msg {
|
||||
Message::Text(txt) => println!("Server: {:?}", txt),
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ extern crate actix_web;
|
||||
extern crate env_logger;
|
||||
|
||||
use actix::prelude::*;
|
||||
use actix_web::{
|
||||
http, middleware, server, fs, ws, App, HttpRequest, HttpResponse, Error};
|
||||
use actix_web::ws::WsWriter;
|
||||
use actix_web::{fs, http, middleware, server, ws, App, Error, HttpRequest, HttpResponse};
|
||||
|
||||
/// do websocket handshake and start `MyWebSocket` actor
|
||||
fn ws_index(r: HttpRequest) -> Result<HttpResponse, Error> {
|
||||
@ -27,7 +27,6 @@ impl Actor for MyWebSocket {
|
||||
|
||||
/// Handler for `ws::Message`
|
||||
impl StreamHandler<ws::Message, ws::ProtocolError> for MyWebSocket {
|
||||
|
||||
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
|
||||
// process websocket messages
|
||||
println!("WS: {:?}", msg);
|
||||
|
Reference in New Issue
Block a user