use tokio::{io::AsyncWriteExt, net::TcpStream}; use crate::{message::Message, player::Player}; pub struct Client { pub server_host: String, pub server_port: u16, pub stream: TcpStream, } impl Client { pub async fn connect(host: impl Into, port: u16) -> anyhow::Result { let host = host.into(); let address = format!("{}:{}", host, port); let stream = TcpStream::connect(address).await?; Ok(Self { server_host: host, server_port: port, stream, }) } pub async fn send_message(&mut self, message: Message) -> anyhow::Result<()> { let message_string = message.encode()?; self.stream.write_all(&message_string.as_bytes()).await?; Ok(()) } pub async fn create_player() -> Option { todo!() } }