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

v3 examples (#364)

This commit is contained in:
Rob Ede
2020-09-12 16:49:45 +01:00
committed by GitHub
parent 3f2b2708c3
commit 49e29a5751
112 changed files with 251 additions and 333 deletions

View File

@ -13,12 +13,11 @@ name = "websocket-tcp-client"
path = "src/client.rs"
[dependencies]
actix = "0.9.0"
actix-web = "2.0.0"
actix-web-actors = "2.0.0"
actix-files = "0.2.1"
actix-rt = "1.0.0"
actix-codec = "0.2.0"
actix = "0.10"
actix-web = "3"
actix-web-actors = "3"
actix-files = "0.3"
actix-codec = "0.3"
rand = "0.7"
bytes = "0.5.3"
@ -28,4 +27,4 @@ env_logger = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = "0.2.4"
tokio-util = "0.2.0"
tokio-util = "0.3"

View File

@ -8,7 +8,7 @@ use tokio_util::codec::FramedRead;
mod codec;
#[actix_rt::main]
#[actix_web::main]
async fn main() {
// Connect to server
let addr = net::SocketAddr::from_str("127.0.0.1:12345").unwrap();
@ -38,7 +38,11 @@ async fn main() {
}
struct ChatClient {
framed: actix::io::FramedWrite<WriteHalf<TcpStream>, codec::ClientChatCodec>,
framed: actix::io::FramedWrite<
codec::ChatRequest,
WriteHalf<TcpStream>,
codec::ClientChatCodec,
>,
}
#[derive(Message)]

View File

@ -65,8 +65,7 @@ impl Decoder for ChatCodec {
}
}
impl Encoder for ChatCodec {
type Item = ChatResponse;
impl Encoder<ChatResponse> for ChatCodec {
type Error = io::Error;
fn encode(
@ -110,8 +109,7 @@ impl Decoder for ClientChatCodec {
}
}
impl Encoder for ClientChatCodec {
type Item = ChatRequest;
impl Encoder<ChatRequest> for ClientChatCodec {
type Error = io::Error;
fn encode(

View File

@ -219,7 +219,7 @@ impl WsChatSession {
}
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init();

View File

@ -31,7 +31,7 @@ pub struct ChatSession {
/// joined room
room: String,
/// Framed wrapper
framed: actix::io::FramedWrite<WriteHalf<TcpStream>, ChatCodec>,
framed: actix::io::FramedWrite<ChatResponse, WriteHalf<TcpStream>, ChatCodec>,
}
impl Actor for ChatSession {
@ -136,7 +136,7 @@ impl Handler<Message> for ChatSession {
impl ChatSession {
pub fn new(
addr: Addr<ChatServer>,
framed: actix::io::FramedWrite<WriteHalf<TcpStream>, ChatCodec>,
framed: actix::io::FramedWrite<ChatResponse, WriteHalf<TcpStream>, ChatCodec>,
) -> ChatSession {
ChatSession {
id: 0,
@ -176,7 +176,7 @@ pub fn tcp_server(_s: &str, server: Addr<ChatServer>) {
// Create server listener
let addr = net::SocketAddr::from_str("127.0.0.1:12345").unwrap();
actix_rt::spawn(async move {
actix_web::rt::spawn(async move {
let server = server.clone();
let mut listener = TcpListener::bind(&addr).await.unwrap();
let mut incoming = listener.incoming();