Skip to content

WebSocket API

Igal edited this page Apr 12, 2017 · 13 revisions

The WebSocket object is passed into many of the event handling methods as an argument named websocket. It implements the javax.websocket.Session interface, and allows you to interact with the connection via the methods below.

close([code][, description])

Closes the connection and optionally returns the numeric code and text description

@param code - integer as per http://docs.oracle.com/javaee/7/api/javax/websocket/CloseReason.CloseCodes.html

@param description - string describing the reason for closing the connection

getApplicationScope():Application

@returns the Application Scope that is associated with this connection

getAsyncRemote()

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#getAsyncRemote--

getBasicRemote()

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#getBasicRemote--

getChannels()

@returns an Array with the names of the channels to which this connection is subscribed

getConnectionManager()

Returns the ConnectionManager for this connection. see ConnectionManager API

getId()

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#getId--

getMaxIdleTimeout()

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#getMaxIdleTimeout--

getOpenSessions()

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#getOpenSessions--

getPathParameters()

@returns a struct with the path parameters that were used in placeholders. For example, if the endpoint is /ws/chat/{channel} and the client connects to /ws/chat/developers, then the struct will have the key channel with the value developers.

see http://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#getPathParameters--

getQueryString()

see http://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#getQueryString--

getRequestURI()

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#getRequestURI--

getSessionScope():Session

@returns the Session Scope that is associated with this connection

getUserProperties()

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#getUserProperties--

getWebsocketSession()

@returns the actual javax.websocket.Session object

isOpen()

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#isOpen--

isSecure()

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#isSecure--

sendText(string message):boolean

Sends the message to the WebSocket client. Returns true if the connection was still open, or false if it was closed.

sendTextAsync(string message):boolean

Sends the message to the WebSocket client asynchronously. Returns true if the connection was still open, or false if it was closed.

setMaxIdleTimeout(long milliseconds)

see https://docs.oracle.com/javaee/7/api/javax/websocket/Session.html#setMaxIdleTimeout-long-

subscribe(string channel)

Subscribes the WebSocket connection to the given channel.

unsubscribe(string channel)

Unsubscribes the WebSocket connection from the given channel.

unsubscribeAll()

Unsubscribes the WebSocket connection from all channels.