[][src]Struct stdweb::web::WebSocket

pub struct WebSocket(_);

The WebSocket object provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.

(JavaScript docs)

Methods

impl WebSocket[src]

pub fn new(url: &str) -> Result<WebSocket, CreationError>[src]

Returns a newly constructed WebSocket.

(JavaScript docs)

pub fn new_with_protocols(
    url: &str,
    protocols: &[&str]
) -> Result<WebSocket, CreationError>
[src]

Returns a newly constructed WebSocket.

(JavaScript docs)

pub fn binary_type(&self) -> SocketBinaryType[src]

Returns the binary type of the web socket. Only affects received messages. The default binary type is Blob.

(JavaScript docs)

pub fn set_binary_type(&self, binary_type: SocketBinaryType)[src]

Sets the binary type of the web socket. Only affects received messages. The default binary type is Blob.

(JavaScript docs)

pub fn buffered_amount(&self) -> u64[src]

Returns the number of bytes of data that have been queued using calls to send() but not yet transmitted to the network. This value resets to zero once all queued data has been sent. This value does not reset to zero when the connection is closed; if you keep calling send(), this will continue to climb.

(JavaScript docs)

pub fn extensions(&self) -> String[src]

Returns the extensions selected by the server. This is currently only the empty string or a list of extensions as negotiated by the connection.

(JavaScript docs)

pub fn protocol(&self) -> String[src]

Returns a string indicating the name of the sub-protocol the server selected; this will be one of the strings specified in the protocols parameter when creating the WebSocket object.

(JavaScript docs)

pub fn ready_state(&self) -> SocketReadyState[src]

Returns the current state of the connection.

(JavaScript docs)

pub fn url(&self) -> String[src]

Returns the URL as resolved by the constructor. This is always an absolute URL.

(JavaScript docs)

pub fn close(&self)[src]

Closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED, this method does nothing.

(JavaScript docs)

pub fn close_with_status(
    &self,
    code: SocketCloseCode,
    reason: &str
) -> Result<(), CloseError>
[src]

Closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED, this method does nothing.

(JavaScript docs)

pub fn send_text(&self, text: &str) -> Result<(), TODO>[src]

Enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value of bufferedAmount by the number of bytes needed to contain the data. If the data can't be sent (for example, because it needs to be buffered but the buffer is full), the socket is closed automatically.

pub fn send_blob(&self, blob: &Blob) -> Result<(), TODO>[src]

Enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value of bufferedAmount by the number of bytes needed to contain the data. If the data can't be sent (for example, because it needs to be buffered but the buffer is full), the socket is closed automatically.

pub fn send_array_buffer(&self, array_buffer: &ArrayBuffer) -> Result<(), TODO>[src]

Enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value of bufferedAmount by the number of bytes needed to contain the data. If the data can't be sent (for example, because it needs to be buffered but the buffer is full), the socket is closed automatically.

pub fn send_bytes(&self, bytes: &[u8]) -> Result<(), TODO>[src]

Enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value of bufferedAmount by the number of bytes needed to contain the data. If the data can't be sent (for example, because it needs to be buffered but the buffer is full), the socket is closed automatically.

Trait Implementations

impl JsSerialize for WebSocket[src]

impl TryFrom<EventTarget> for WebSocket[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl TryFrom<WebSocket> for Reference[src]

type Error = Void

The type returned in the event of a conversion error.

impl TryFrom<Reference> for WebSocket[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl<'_r> TryFrom<&'_r Reference> for WebSocket[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl TryFrom<Value> for WebSocket[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl<'_r> TryFrom<&'_r Value> for WebSocket[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl InstanceOf for WebSocket[src]

impl ReferenceType for WebSocket[src]

impl IEventTarget for WebSocket[src]

fn add_event_listener<T, F>(&self, listener: F) -> EventListenerHandle where
    T: ConcreteEvent,
    F: FnMut(T) + 'static, 
[src]

Adds given event handler to the list of event listeners for the specified EventTarget on which it's called. Read more

fn dispatch_event<T: IEvent>(&self, event: &T) -> Result<bool, TODO>[src]

Dispatches an Event at this EventTarget, invoking the affected event listeners in the appropriate order. Read more

impl From<WebSocket> for EventTarget[src]

impl From<WebSocket> for Reference[src]

impl Eq for WebSocket[src]

impl AsRef<Reference> for WebSocket[src]

impl PartialEq<WebSocket> for WebSocket[src]

impl Clone for WebSocket[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for WebSocket[src]

Auto Trait Implementations

impl Send for WebSocket

impl Sync for WebSocket

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]