I'm trying to make an asynchronous WebSocket server (my own implementation). I have the following code:
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut listener = TcpListener::bind("127.0.0.1:8080").await?;
loop {
let (socket, _) = listener.accept().await?;
tokio::spawn(async move {
let mut buffer = [0u8; 512];
let stuff = match socket.read(&mut buffer).await {
Ok(n) => buffer[..n].to_vec(),
Err(_) => return,
};
});
}
}
Now what do I do? According to the spec, I have to check the FIN bit, opcode, etc. but how do I do that. The FIN bit is just 1 bit, how are we supposed to get that out of a u8 array? Examples would help greatly.