Fix producer: now listens to incoming packets

This commit is contained in:
Tony Garnock-Jones 2020-05-19 10:55:23 +02:00
parent 99c0be80a3
commit aab0158d15
1 changed files with 16 additions and 31 deletions

View File

@ -1,11 +1,9 @@
use syndicate::value::Value; use syndicate::value::Value;
use syndicate::packets::{ClientCodec, C2S, S2C, Action}; use syndicate::packets::{ClientCodec, C2S, S2C, Action};
use tokio::io::AsyncRead;
use tokio::net::TcpStream; use tokio::net::TcpStream;
use tokio_util::codec::Framed; use tokio_util::codec::Framed;
use futures::SinkExt; use futures::{SinkExt, StreamExt, poll};
use futures::StreamExt; use std::task::Poll;
use std::future::Future;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -13,26 +11,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
ClientCodec::standard()); ClientCodec::standard());
frames.send(C2S::Connect(Value::from("chat").wrap())).await?; frames.send(C2S::Connect(Value::from("chat").wrap())).await?;
// let m = Action::Message(
// Value::simple_record("Says", vec![
// Value::from("producer").wrap(),
// Value::from(123).wrap(),
// ]).wrap());
// loop {
// frames.send(C2S::Turn(vec![
// m.clone(),
// m.clone(),
// m.clone(),
// m.clone(),
// m.clone(),
// m.clone(),
// m.clone(),
// m.clone(),
// m.clone(),
// m.clone(),
// ])).await?;
// }
let mut counter: u64 = 0; let mut counter: u64 = 0;
loop { loop {
counter = counter + 1; counter = counter + 1;
@ -41,12 +19,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Value::from("producer").wrap(), Value::from("producer").wrap(),
Value::from(counter).wrap(), Value::from(counter).wrap(),
]).wrap())])).await?; ]).wrap())])).await?;
// match frames.poll_read() { loop {
// None => (), match poll!(frames.next()) {
// Some(res) => match res { Poll::Pending => break,
// S2C::Ping() => frames.send(C2S::Pong()).await?, Poll::Ready(None) => {
// other => print!("{:?}\n", other), print!("Server closed connection");
// } return Ok(());
// } }
Poll::Ready(Some(res)) => {
let p = res?;
print!("{:?}\n", p);
if let S2C::Ping() = p { frames.send(C2S::Pong()).await? }
}
}
}
} }
} }