pub struct Client { /* private fields */ }
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a empty client
Examples found in repository?
examples/event.rs (line 6)
4fn main() -> Pod {
5 let _log2 = log2::start();
6 let mut ws = ws2::Client::new();
7
8 ws.connect("ws://172.16.210.211:5600")?;
9
10 loop {
11 let event = ws.recv(0.01);
12 match event {
13 ws2::client::Event::Open(_) => {
14 info!("open");
15 if let Err(e) = ws.send("hello world") {
16 error!("{e}");
17 }
18 }
19 ws2::client::Event::Close => {
20 info!("close");
21 break;
22 }
23 ws2::client::Event::Text(msg) => {
24 info!("{msg}");
25 }
26 ws2::client::Event::Binary(_) => {}
27 ws2::client::Event::Timeout => {}
28 ws2::client::Event::Error(error) => {
29 error!("{error}");
30 }
31 }
32 }
33
34 Ok(())
35}
Sourcepub fn connect(&mut self, url: &str) -> Pod
pub fn connect(&mut self, url: &str) -> Pod
Examples found in repository?
examples/event.rs (line 8)
4fn main() -> Pod {
5 let _log2 = log2::start();
6 let mut ws = ws2::Client::new();
7
8 ws.connect("ws://172.16.210.211:5600")?;
9
10 loop {
11 let event = ws.recv(0.01);
12 match event {
13 ws2::client::Event::Open(_) => {
14 info!("open");
15 if let Err(e) = ws.send("hello world") {
16 error!("{e}");
17 }
18 }
19 ws2::client::Event::Close => {
20 info!("close");
21 break;
22 }
23 ws2::client::Event::Text(msg) => {
24 info!("{msg}");
25 }
26 ws2::client::Event::Binary(_) => {}
27 ws2::client::Event::Timeout => {}
28 ws2::client::Event::Error(error) => {
29 error!("{error}");
30 }
31 }
32 }
33
34 Ok(())
35}
pub fn is_open(&self) -> bool
Sourcepub fn recv(&mut self, timeout: f32) -> Event
pub fn recv(&mut self, timeout: f32) -> Event
Receive the events, timeout is decimal seconds
Examples found in repository?
examples/event.rs (line 11)
4fn main() -> Pod {
5 let _log2 = log2::start();
6 let mut ws = ws2::Client::new();
7
8 ws.connect("ws://172.16.210.211:5600")?;
9
10 loop {
11 let event = ws.recv(0.01);
12 match event {
13 ws2::client::Event::Open(_) => {
14 info!("open");
15 if let Err(e) = ws.send("hello world") {
16 error!("{e}");
17 }
18 }
19 ws2::client::Event::Close => {
20 info!("close");
21 break;
22 }
23 ws2::client::Event::Text(msg) => {
24 info!("{msg}");
25 }
26 ws2::client::Event::Binary(_) => {}
27 ws2::client::Event::Timeout => {}
28 ws2::client::Event::Error(error) => {
29 error!("{error}");
30 }
31 }
32 }
33
34 Ok(())
35}
Sourcepub fn send<M>(&self, msg: M) -> Pod
pub fn send<M>(&self, msg: M) -> Pod
Examples found in repository?
examples/event.rs (line 15)
4fn main() -> Pod {
5 let _log2 = log2::start();
6 let mut ws = ws2::Client::new();
7
8 ws.connect("ws://172.16.210.211:5600")?;
9
10 loop {
11 let event = ws.recv(0.01);
12 match event {
13 ws2::client::Event::Open(_) => {
14 info!("open");
15 if let Err(e) = ws.send("hello world") {
16 error!("{e}");
17 }
18 }
19 ws2::client::Event::Close => {
20 info!("close");
21 break;
22 }
23 ws2::client::Event::Text(msg) => {
24 info!("{msg}");
25 }
26 ws2::client::Event::Binary(_) => {}
27 ws2::client::Event::Timeout => {}
28 ws2::client::Event::Error(error) => {
29 error!("{error}");
30 }
31 }
32 }
33
34 Ok(())
35}
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl !Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more