Struct Client

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

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}
Source

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}
Source

pub fn is_open(&self) -> bool

Source

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}
Source

pub fn send<M>(&self, msg: M) -> Pod
where M: Into<Message>,

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}
Source

pub fn close(&self)

Close the socket

Source

pub fn process<F: Handler>(&mut self, handler: &mut F, timeout: f32) -> Pod

Process events with decimal seconds timeout, or [INFINITE]

Examples found in repository?
examples/client.rs (line 31)
24fn main() -> Pod {
25    let _log2 = log2::start();
26    let url = "wss://stream.binance.com:9443/ws/btcusdt@miniTicker";
27    let mut client = ws2::connect(url)?;
28    let mut workder = Worker {};
29
30    loop {
31        let _ = client.process(&mut workder, 0.5);
32        // do other stuff
33    }
34}

Trait Implementations§

Source§

impl Drop for Client

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Pollable for Client

Source§

fn signal(&self) -> ArcMutex2<OptionSignal>

shared signal channel
Source§

fn id(&self) -> i32

channel id

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T