pub enum MessageType {
Text,
Binary,
Ping,
Pong,
Close,
}Expand description
Represents the type of a WebSocket message.
This enum categorizes messages into their protocol-defined types. Most application logic will work with text and binary messages, while control frames (Ping, Pong, Close) are typically handled by the framework automatically.
§Examples
use wsforge::prelude::*;
match msg.message_type() {
MessageType::Text => {
println!("Processing text message");
}
MessageType::Binary => {
println!("Processing binary data");
}
MessageType::Ping => {
println!("Received ping (will auto-respond with pong)");
}
MessageType::Pong => {
println!("Received pong");
}
MessageType::Close => {
println!("Client disconnecting");
}
}Variants§
Text
Text message containing UTF-8 encoded string data.
This is the most common message type for:
- JSON data
- Plain text chat messages
- Commands and instructions
- XML or other text-based formats
Binary
Binary message containing raw byte data.
Use this for:
- Images, audio, video files
- Protocol buffers, MessagePack
- Custom binary protocols
- Large data transfers
Ping
Ping frame for connection keep-alive.
Servers send pings to check if the connection is still active. Clients should respond with a Pong frame (handled automatically).
Pong
Pong frame responding to a Ping.
This is automatically sent in response to Ping frames. You rarely need to create these manually.
Close
Close frame indicating connection termination.
Sent when either side wants to close the connection gracefully. Contains optional close code and reason.
Trait Implementations§
Source§impl Clone for MessageType
impl Clone for MessageType
Source§fn clone(&self) -> MessageType
fn clone(&self) -> MessageType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more