Browse Source

client uses mio tcpsocket

pbs
Jake Probst 5 years ago
parent
commit
377392b8bd
  1. 6
      src/common/client.rs

6
src/common/client.rs

@ -19,10 +19,10 @@ pub struct Client<P, E> {
}
impl<P: ServerPacket + std::fmt::Debug, E: std::fmt::Debug> Client<P, E> {
pub fn new(socket: net::TcpStream, state: Box<dyn ServerState<Packet = P, PacketError = E>>) -> Client<P, E> {
pub fn new(socket: mio::tcp::TcpStream, state: Box<dyn ServerState<Packet = P, PacketError = E>>) -> Client<P, E> {
let mut client = Client {
running: true,
socket: mio::tcp::TcpStream::from_stream(socket).expect("could not convert socket to nonblocking"),
socket: socket,
cipher_in: Box::new(NullCipher {}),
cipher_out: Box::new(NullCipher {}),
state: state,
@ -62,7 +62,6 @@ impl<P: ServerPacket + std::fmt::Debug, E: std::fmt::Debug> Client<P, E> {
// TODO: this may need to pad to 8 bytes for bb cipher
fn send(&mut self, pkt: &dyn PSOPacket) {
let buf = pkt.as_bytes();
println!("[send]: {:X?}", buf);
let mut cbuf = self.cipher_out.encrypt(&buf).unwrap();
self.send_buffer.append(&mut cbuf);
self.send_data();
@ -97,7 +96,6 @@ impl<P: ServerPacket + std::fmt::Debug, E: std::fmt::Debug> Client<P, E> {
}
},
Err(err) => {
println!("error recv-ing packet with {:?}: {:?}", self.socket, err);
match err {
PacketNetworkError::ClientDisconnected => self.running = false,
_ => println!("error recv-ing packet with {:?}: {:?}", self.socket, err),

Loading…
Cancel
Save