1
This commit is contained in:
parent
f4868cdfcf
commit
c2fe49bcd0
@ -18,7 +18,10 @@ use std::sync::Mutex;
|
|||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use bytes::{Buf, BufMut, Bytes};
|
use bytes::{Buf, BufMut, Bytes};
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
//use serde::de::Unexpected::Bytes;
|
use tokio::io::{AsyncWriteExt, Ready};
|
||||||
|
use tokio::net::TcpStream;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::io::Interest;
|
||||||
|
|
||||||
const MAX_PACKET_LEN: usize = 1024 * 64;
|
const MAX_PACKET_LEN: usize = 1024 * 64;
|
||||||
|
|
||||||
@ -45,6 +48,9 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
|
|||||||
Ok(ws::Message::Ping(msg)) => ctx.pong(&msg),
|
Ok(ws::Message::Ping(msg)) => ctx.pong(&msg),
|
||||||
Ok(ws::Message::Text(text)) => ctx.text(text),
|
Ok(ws::Message::Text(text)) => ctx.text(text),
|
||||||
Ok(ws::Message::Binary(bin)) => {
|
Ok(ws::Message::Binary(bin)) => {
|
||||||
|
println!("recv_buf:{0}", bin.len());
|
||||||
|
//self.down_stream.write_all(&bin);
|
||||||
|
/*
|
||||||
let buf_len = bin.len();
|
let buf_len = bin.len();
|
||||||
if buf_len > 0 {
|
if buf_len > 0 {
|
||||||
let mut already_read_bytes: usize = 0;
|
let mut already_read_bytes: usize = 0;
|
||||||
@ -81,7 +87,7 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
|
|||||||
//self.recv_buf[..0].copy_from_slice(&bin);
|
//self.recv_buf[..0].copy_from_slice(&bin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
@ -113,10 +119,37 @@ async fn index(req: HttpRequest, stream: web::Payload, data: web::Data<AppStateW
|
|||||||
*counter += 1; // <- access counter inside MutexGuard
|
*counter += 1; // <- access counter inside MutexGuard
|
||||||
|
|
||||||
format!("Request number: {counter}"); // <- response with count
|
format!("Request number: {counter}"); // <- response with count
|
||||||
let resp = ws::start(MyWs {
|
let ws_client = MyWs {
|
||||||
recv_buf_len: 0,
|
recv_buf_len: 0,
|
||||||
recv_buf: BytesMut::with_capacity(1024 * 64 * 2)
|
recv_buf: BytesMut::with_capacity(1024 * 64 * 2),
|
||||||
}, &req, stream);
|
};
|
||||||
|
{
|
||||||
|
let mut down_stream = TcpStream::connect("192.168.100.39:7616").await?;
|
||||||
|
down_stream.set_nodelay(true);
|
||||||
|
//down_stream.set_nonblocking(true)?;
|
||||||
|
tokio::spawn(async move {
|
||||||
|
loop {
|
||||||
|
let ready = down_stream.ready(Interest::READABLE | Interest::WRITABLE).await;
|
||||||
|
match ready {
|
||||||
|
Ok(r) => {
|
||||||
|
{
|
||||||
|
if r.is_readable() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
if r.is_writable() {
|
||||||
|
down_stream.write_all(b"hello world!").await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let resp = ws::start(ws_client, &req, stream);
|
||||||
println!("{:?}", resp);
|
println!("{:?}", resp);
|
||||||
resp
|
resp
|
||||||
}
|
}
|
||||||
@ -141,8 +174,6 @@ fn main() {
|
|||||||
println!("hello2");
|
println!("hello2");
|
||||||
});
|
});
|
||||||
|
|
||||||
//App::run();
|
|
||||||
//t1.join().unwrap();
|
|
||||||
println!("hello3");
|
println!("hello3");
|
||||||
while true {
|
while true {
|
||||||
thread::sleep(Duration::from_secs(10));
|
thread::sleep(Duration::from_secs(10));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user