-
Notifications
You must be signed in to change notification settings - Fork 0
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
7769131
commit 955c773
Showing
22 changed files
with
659 additions
and
286 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
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,50 @@ | ||
use em_as_net::{ | ||
client::websocket::{ | ||
AsyncWebSocketClient, ReadResult, WebSocketRead, WebSocketSendMessageType, WebSocketWrite, | ||
}, | ||
core::{tcp::TcpStream, tls::TlsStream}, | ||
}; | ||
use rand::thread_rng; | ||
use url::Url; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let uri = Url::parse("wss://ws.vi-server.org:443/mirror/").unwrap(); | ||
let stream = TcpStream::connect(&uri).await.unwrap(); | ||
println!("TCP Connected"); | ||
let mut tls_stream = TlsStream::connect(stream, &uri).await.unwrap(); | ||
println!("TLS Handshake Done"); | ||
let mut buffer = [0u8; 4096]; | ||
let rng = thread_rng(); | ||
let mut websocket = | ||
AsyncWebSocketClient::open(&mut tls_stream, &mut buffer, &uri, rng, None, None) | ||
.await | ||
.unwrap(); | ||
println!("WebSocket Connected"); | ||
websocket | ||
.write( | ||
&mut tls_stream, | ||
&mut buffer, | ||
WebSocketSendMessageType::Text, | ||
true, | ||
"Hello World".as_bytes(), | ||
) | ||
.await | ||
.unwrap(); | ||
println!("Message Sent"); | ||
loop { | ||
let message = websocket | ||
.try_read(&mut tls_stream, &mut buffer) | ||
.await | ||
.unwrap() | ||
.unwrap(); | ||
match message { | ||
ReadResult::Text(text) => { | ||
assert_eq!("Hello World".to_string(), text); | ||
println!("Received message: {}", text); | ||
} | ||
_ => panic!("Expected 'Hello World' as text message."), | ||
} | ||
break; | ||
} | ||
} |
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
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
Oops, something went wrong.