Skip to main content

%CSP.WebSocket

class %CSP.WebSocket extends %Library.RegisteredObject, %CSP.Page

The %CSP.WebSocket object serves as an event handler for communication between client and server using the WebSocket protocol (RFC 6455). All WebSocket servers derive from %CSP.WebSocket.

Property Inventory

Method Inventory

Parameters

parameter NOCHARSETCONVERT = 1;
Inherited description: Specifies if we wish to turn off charset conversion for this page. Normally CSP uses the tables built into InterSystems IRIS to convert between different charset's, however if you do not have a charset available you may wish to turn this off to avoid getting the error page saying that this charset is not installed. Then the data will be output and read in using RAW mode. This can be overridden using the <CSP:CONTENT NOCHARSETCONVERT=1> tag, or by setting the %response.NoCharSetConvert property in the OnPreHTTP() method.
parameter UseSession = 1;
Inherited description: This parameter controls the CSP session support. By default CSP will use a persistent session which holds a license until the session is ended or times out. If you override this then this CSP page will use a transient session which is never persisted.

Properties

property AtEnd as %Boolean [ InitialExpression = 1 ];
The AtEnd property is set to true (1) when, during a read, the WebSocket server has reached the end of the current data frame.
Property methods: AtEndDisplayToLogical(), AtEndGet(), AtEndIsValid(), AtEndLogicalToDisplay(), AtEndNormalize(), AtEndSet()
property BinaryData as %Boolean [ InitialExpression = 0 ];
This property determines whether the data streams transmitted between the client and server should be treated as binary. The default setting is to treat the incoming and outgoing data as UTF-8 encoded text.

This property may be set to one of the following:
  • BinaryData=0 - UTF-8 encoded text.
  • BinaryData=1 - Binary Data.
Property methods: BinaryDataDisplayToLogical(), BinaryDataGet(), BinaryDataIsValid(), BinaryDataLogicalToDisplay(), BinaryDataNormalize(), BinaryDataSet()
property GWClientAddress as %String;
The address through which a WebSocket operating asynchronously (SharedConnection=1) can communicate with the hosting CSP Gateway.
Property methods: GWClientAddressDisplayToLogical(), GWClientAddressGet(), GWClientAddressIsValid(), GWClientAddressLogicalToDisplay(), GWClientAddressLogicalToOdbc(), GWClientAddressNormalize(), GWClientAddressSet()
property NoDataFraming as %Boolean [ InitialExpression = 0 ];
This property determines whether formal data framing should occur between the Web Gateway and InterSystems IRIS
  • NoDataFraming=0 - Use the READ and WRITE methods in this class to manage I/O with the WebSocket.
  • NoDataFraming=1 - Use the basic ObjectScript READ and WRITE commands to manage I/O with the WebSocket (SharedConnection cannot be set with this mode).
Property methods: NoDataFramingDisplayToLogical(), NoDataFramingGet(), NoDataFramingIsValid(), NoDataFramingLogicalToDisplay(), NoDataFramingNormalize(), NoDataFramingSet()
property SessionEndOnClose as %Boolean [ InitialExpression = 0 ];
This property determines whether WebSocket closure forces the associated CSP session to end. Must be set in either Server() or OnPostServer(). For WebSockets operating asynchronously, only takes effect if EndServer() is called in Server().

This property may be set to one of the following:
  • SessionEndOnClose=0 - Do not force the CSP session to end when the web socket closes. (For synchronous web sockets, the CSP session may still end depending on its EndSession property.)
  • SessionEndOnClose=1 - Ensure that the CSP session ends when the web socket closes.
Property methods: SessionEndOnCloseDisplayToLogical(), SessionEndOnCloseGet(), SessionEndOnCloseIsValid(), SessionEndOnCloseLogicalToDisplay(), SessionEndOnCloseNormalize(), SessionEndOnCloseSet()
property SessionId as %String;
The CSP Session ID from which this WebSocket was created.
Property methods: SessionIdDisplayToLogical(), SessionIdGet(), SessionIdIsValid(), SessionIdLogicalToDisplay(), SessionIdLogicalToOdbc(), SessionIdNormalize(), SessionIdSet()
property SharedConnection as %Boolean [ InitialExpression = 0 ];
This property determines whether the communication between the client and WebSocket server should be over a dedicated Gateway conection or over a pool of shared connections. It may be set to one of the following:
  • SharedConnection=0 - The WebSocket server communicates with the client via a dedicated Gateway connection. In this mode of operation the hosting connection is effectively 'private' to the application session.
  • SharedConnection=1 - The WebSocket server communicates asynchronously with the client via a fixed number of shared Gateway connections.
Property methods: SharedConnectionDisplayToLogical(), SharedConnectionGet(), SharedConnectionIsValid(), SharedConnectionLogicalToDisplay(), SharedConnectionNormalize(), SharedConnectionSet()
property WebSocketID as %String;
The unique identity of this WebSocket.
Property methods: WebSocketIDDisplayToLogical(), WebSocketIDGet(), WebSocketIDIsValid(), WebSocketIDLogicalToDisplay(), WebSocketIDLogicalToOdbc(), WebSocketIDNormalize(), WebSocketIDSet()

Methods

method EndServer() as %Status
Gracefully terminate the WebSocket Server.
method Initialize(WebSocketID As %String = "", GWClientAddress As %String = "") as %Status
Internal method to initialize the WebSocket Class.
method InitializeServer() as %Status
Internal method to initialize the WebSocket Server.
method OnClientMessage(data As %String = "", close As %Integer) as %Status
Event handler for the ClientMessage event: this method is only relevant to WebSockets operating in Asynchronous mode. In other words WebSockets for which the SharedConnection flag is set. If OnClientMessage() successfully processes the client message it must return with 1.
method OnPostServer() as %Status
Event handler for the PostServer event: this is invoked after closing the WebSockets Server.
method OnPreServer() as %Status
Event handler for the PreServer event: this is invoked before starting the WebSockets Server. Changes to the SharedConnection flag must be made here.
method OpenServer(WebSocketID As %String = "") as %Status
Method to open an existing WebSocket Server. Only a WebSocket operating asynchronously (SharedConnection=1) can be accessed using this method.
method Read(ByRef len As %Integer = 32656, ByRef sc As %Status, timeout As %Integer = 86400) as %String
Reads up to len characters from the client. If the call is successful the status (sc) will be returned as $$$OK, otherwise an error code of $$$CSPWebSocketTimeout indicates a timeout and $$$CSPWebSocketClosed indicates that the client has terminated the WebSocket.
final classmethod SendAsyncMessage(websocketid As %String, gwclientaddress As %String) as %Status
method Server() as %Status
The WebSocket Server. Use the Read() and Write() methods to receive data from, and send data to, the client. Call the EndServer() method to gracefully terminate the WebSocket Server. A WebSocket operating asynchronously (SharedConnection=1) can exit this method (using Quit) and subsequently open the WebSocket using the OpenServer() method.
method Write(data As %String) as %Status
Write to the client.

Inherited Members

Inherited Methods

FeedbackOpens in a new tab