Name
WebSocket — a bidirectional socket-like network connection
Inherits from
EventTarget
Synopsis
A WebSocket represents a long-lived, bidirectional,
socket-like network connection to a server that supports the
WebSocket protocol. This is a fundamentally different networking
model than the request/response model of HTTP. Create a new
connection with the WebSocket()
constructor. Use send()
to send
textual messages to the server, and register a handler for message
events to receive messages from the server. See Web Sockets for further details.
WebSockets are a new Web API and, at the time of this writing, are not supported by all browsers.
Constructor
new
WebSocket
(
string
url
,
[
string
[]
protocols
])
The WebSocket()
constructor
creates a new WebSocket object and begins the (asynchronous) process
of establishing a connection to a WebSocket server. The
url
argument specifies the server to
connect to and must be an absolute URL that uses the ws://
or wss://
URL scheme. The
protocols
argument is an array of
subprotocol names. If the argument is specified, it is the client’s
way of telling the server which communication protocols or which
protocol versions it is able to “speak.” The server must choose one
and inform the client as part of the connection process. protocols
may also be specified as a
single string instead of an array: in this case, it is treated as an
array of length 1.
Constants
These constants are the values of the readyState
property.
unsigned short
CONNECTING
= 0The connection process ...
Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.