Skip to content

WebSocket API

Igal edited this page Apr 8, 2017 · 13 revisions

WebSocket API

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.

getApplicationScope()

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

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

getRequestURI()

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

getSessionScope()

@returns the Session Scope that is associated with this connection

getUserProperties()

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

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)

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.

TODO: add close() and close(reason)

Clone this wiki locally