Learn more about WebSocket on Wikipedia
SendUpgrademethod on received HTTP
Requestobject, for example:
SendUpgradeis called and WebSocket object is available, it can immediately be used to perform sends and other operations allowed on WebSocket.
WebSocket.ToUInt64(), in opposite, to create a WebSocket object just pass the UInt64 ID to WebSocket constructor:
SendUpgrademethod is called, the approving WebSocket upgrade HTTP Response is sent immediately. To be able to get the WebSocket ID before calling
SendUpgrade, call the
SendUpgrademethod on Request has the following signature:
groupName: string identifying WebSocket "group" on which subsequent events for this WebSocket should arrive.
cookies: Cookies that should be set on returned WebSocket upgrade HTTP response.
headers: Custom headers that should be set on returned WebSocket upgrade HTTP response.
session: a session object that is attached to this WebSocket in subsequent events.
ToUInt64()), and of course, perform data sends and disconnect.
Handle.WebSocketmethod should be used, for example:
Textand the only registered handler is for
Binarythen WebSocket connection will be closed with a type:
WS_CLOSE_CANT_ACCEPT_DATA. Same applies for vice-versa scenario.
Handle.WebSocketDisconnectmethod should be used, for example:
WebSocketobject contains the following notable methods:
isTextparameter you can specify if your WebSocket data should be sent as
Binaryframe (see RFC6455)
Response.ConnectionFlagsparameter is used to manipulate corresponding WebSocket connection: for example, if you want to close the connection with client or send data and then close the connection. Please see section about handling responses for more information on
Send) will actually be performed is not guaranteed to be the same as the order in which they were initiated.
UInt64 ToUInt64(): identifier that represents the WebSocket, normally used for storage in user code.
IAppsSession Session: session object that was initially attached on WebSocket if any.
static WebSocket Current: static object identifying currently active WebSocket.
enum WebSocketCloseCodes: list of available WebSocket disconnect codes, according to RFC6455.
Boolean IsDead(): checks if WebSocket is already disconnected or invalid.
Sessionobject contains the reference to the last active WebSocket:
ActiveWebsocket, which is associated with this session.
ActiveWebsockethowever can be
nullwhen session has no WebSocket attached to it.