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.

Documentation WebSocket by Mozilla Contributors, licensed under CC-BY-SA 2.5.

See also:

Static variables

@:value(3)staticinlineread onlyCLOSED:Int = 3

@:value(2)staticinlineread onlyCLOSING:Int = 2

@:value(0)staticinlineread onlyCONNECTING:Int = 0

@:value(1)staticinlineread onlyOPEN:Int = 1

Constructor

new(url:String, protocols:Array<String>)

new(url:String)

new(url:String, protocols:String)

Throws:

null

DOMError

Variables

binaryType:BinaryType

The binary data type used by the connection.

read onlybufferedAmount:Int

The number of bytes of queued data.

read onlyextensions:String

The extensions selected by the server.

onclose:Function

An event listener to be called when the connection is closed.

onerror:Function

An event listener to be called when an error occurs.

onmessage:Function

An event listener to be called when a message is received from the server.

onopen:Function

An event listener to be called when the connection is opened.

read onlyprotocol:String

The sub-protocol selected by the server.

read onlyreadyState:Int

The current state of the connection.

read onlyurl:String

The absolute URL of the WebSocket.

Methods

close(?code:Int, ?reason:String):Void

Throws:

null

DOMError

send(data:ArrayBufferView):Void

send(data:String):Void

send(data:Blob):Void

send(data:ArrayBuffer):Void

Throws:

null

DOMError

Inherited Variables

Inherited Methods

Defined by EventTarget

addEventListener(type:String, listener:Function, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

addEventListener(type:String, listener:EventListener, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

Register an event handler of a specific event type on the EventTarget.

Throws:

null

DOMError

dispatchEvent(event:Event):Bool

Dispatch an event to this EventTarget.

Throws:

null

DOMError

removeEventListener(type:String, listener:Function, ?options:EitherType<EventListenerOptions, Bool>):Void

removeEventListener(type:String, listener:EventListener, ?options:EitherType<EventListenerOptions, Bool>):Void

Removes an event listener from the EventTarget.

Throws:

null

DOMError