Struct Server

Source
pub struct Server { /* private fields */ }
Expand description

WebSockets server implementation.

Implementations§

Source§

impl Server

Source

pub fn addr(&self) -> &SocketAddr

Returns the address this server is listening on

Source

pub fn broadcaster(&self) -> Broadcaster

Returns a Broadcaster that can be used to send messages on all connections.

Source

pub fn start<M: Metadata, S: Middleware<M>>( addr: &SocketAddr, handler: Arc<MetaIoHandler<M, S>>, meta_extractor: Arc<dyn MetaExtractor<M>>, allowed_origins: Option<Vec<Origin>>, allowed_hosts: Option<Vec<Host>>, request_middleware: Option<Arc<dyn RequestMiddleware>>, stats: Option<Arc<dyn SessionStats>>, executor: UninitializedExecutor, max_connections: usize, max_payload_bytes: usize, max_in_buffer_capacity: usize, max_out_buffer_capacity: usize, ) -> Result<Server>
where S::Future: Unpin, S::CallFuture: Unpin,

Starts a new WebSocket server in separate thread. Returns a Server handle which closes the server when droped.

Source§

impl Server

Source

pub fn wait(self) -> Result<()>

Consumes the server and waits for completion

Examples found in repository?
examples/ws.rs (line 15)
4fn main() {
5	let mut io = IoHandler::default();
6	io.add_sync_method("say_hello", |_params| {
7		println!("Processing");
8		Ok(Value::String("hello".to_owned()))
9	});
10
11	let server = ServerBuilder::new(io)
12		.start(&"0.0.0.0:3030".parse().unwrap())
13		.expect("Server must start with no issues");
14
15	server.wait().unwrap()
16}
Source

pub fn close(self)

Closes the server and waits for it to finish

Source

pub fn close_handle(&self) -> CloseHandle

Returns a handle to the server that can be used to close it while another thread is blocking in wait.

Trait Implementations§

Source§

impl Debug for Server

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Server

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Server

§

impl !RefUnwindSafe for Server

§

impl Send for Server

§

impl Sync for Server

§

impl Unpin for Server

§

impl !UnwindSafe for Server

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