-
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.
refactoring and adding non-tls example
- Loading branch information
1 parent
955c773
commit f58e4bb
Showing
20 changed files
with
127 additions
and
1,480 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,47 @@ | ||
use em_as_net::{ | ||
client::websocket::{ | ||
AsyncWebSocketClient, ReadResult, WebSocketRead, WebSocketSendMessageType, WebSocketWrite, | ||
}, | ||
core::tcp::TcpStream, | ||
}; | ||
use rand::thread_rng; | ||
use url::Url; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let uri = Url::parse("ws://ws.vi-server.org:80/mirror/").unwrap(); | ||
let mut stream = TcpStream::connect(&uri).await.unwrap(); | ||
println!("TCP Connected"); | ||
let mut buffer = [0u8; 4096]; | ||
let rng = thread_rng(); | ||
let mut websocket = AsyncWebSocketClient::open(&mut stream, &mut buffer, &uri, rng, None, None) | ||
.await | ||
.unwrap(); | ||
println!("WebSocket Connected"); | ||
websocket | ||
.write( | ||
&mut stream, | ||
&mut buffer, | ||
WebSocketSendMessageType::Text, | ||
true, | ||
"Hello World".as_bytes(), | ||
) | ||
.await | ||
.unwrap(); | ||
println!("Message Sent"); | ||
loop { | ||
let message = websocket | ||
.try_read(&mut 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; | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.