mirror of
https://github.com/actix/examples
synced 2025-06-28 09:50:36 +02:00
v3 examples (#364)
This commit is contained in:
@ -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"
|
||||
|
@ -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)]
|
||||
|
@ -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(
|
||||
|
@ -219,7 +219,7 @@ impl WsChatSession {
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_rt::main]
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init();
|
||||
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user