-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.rs
30 lines (26 loc) · 933 Bytes
/
client.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use structopt::StructOpt;
use yarws::{connect, Error};
#[derive(StructOpt, Debug)]
struct Args {
#[structopt(default_value = "ws://127.0.0.1:9001")]
url: String,
}
// Sends different sizes of text messages to the echo server.
// Expect response to match the request.
#[tokio::main]
async fn main() -> Result<(), Error> {
let args = Args::from_args();
// connect to the server and switch to text only mode
let mut socket = connect(&args.url).await?.into_text();
let data = "01234567890abcdefghijklmnopqrstuvwxyz"; //36 characters
let sizes = vec![1, 36, 125, 126, 127];
for size in sizes {
// create request with `size` number of characters
let rep = size / data.len() + 1;
let req = &data.repeat(rep)[0..size];
socket.send(req).await?; // send request
let rsp = socket.try_recv().await?; // receive response
assert_eq!(req, rsp);
}
Ok(())
}