-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39dba57
commit 19f0b07
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use futures_util::{SinkExt, StreamExt}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let ws = tokio_tungstenite_wasm::connect("wss://echo.websocket.org/") | ||
.await | ||
.unwrap(); | ||
let (mut sender, mut receiver) = ws.split(); | ||
|
||
println!("Connected to echo server."); | ||
|
||
let msg = receiver.next().await.unwrap().unwrap(); | ||
assert!(msg.into_text().unwrap().starts_with("Request served by")); | ||
|
||
println!("Recieved initial connection message."); | ||
|
||
let payload = "This is a test message."; | ||
sender | ||
.send(tokio_tungstenite_wasm::Message::text(payload)) | ||
.await | ||
.unwrap(); | ||
|
||
println!("Sent payload to echo server. Waiting for response..."); | ||
|
||
let msg = receiver.next().await.unwrap().unwrap(); | ||
assert_eq!(msg, tokio_tungstenite_wasm::Message::text(payload)); | ||
|
||
println!("Received and validated response.") | ||
} |