IPWorks WebSockets 2020 Kotlin Edition

Questions / Feedback?

WebSocketOpenRequest Event

Fired when a client attempts to open a WebSocket.

Syntax

public open class DefaultWebsocketserverEventListener : WebsocketserverEventListener {
  ...
  public override fun webSocketOpenRequest(e: WebsocketserverWebSocketOpenRequestEvent) {}
  ...
}

public class WebsocketserverWebSocketOpenRequestEvent {
  val connectionId: String?
  val requestURI: String?
  val hostHeader: String?
  val originHeader: String?
  var subProtocols: String?
  val extensions: String?
  val requestHeaders: String?
  var statusCode: Int
  var responseHeaders: String?
}

Remarks

This event fires when a client connects. It provides an opportunity to inspect the WebSocket request and either accept or reject the connection attempt.

By default, the component will accept the connection. You do not need to set anything to accept the connection. The component will return a StatusCode of 101 to the connecting client and the request will proceed as normal. To reject a connection, set StatusCode to an HTTP error code, such as 401.

ConnectionId identifies the connecting client.

RequestURI provides the URI requested by the connecting client. This may be used to implement logic to select appropriate SubProtocols or determine if the connection should be accepted based on access restrictions to the URI.

HostHeader holds the value of the Host header sent by the client.

OriginHeader holds the value of the Origin header sent by the client.

SubProtocols holds a comma separated list of subprotocols sent by the client (if any). Set SubProtocols to the selected value from the list sent by the client. The component will return this value to the client as the subprotocol the server has selected.

Extensions provides a list of extensions supported by the client.

RequestHeaders contains the HTTP headers sent in the request by the connecting client.

StatusCode determines success or failure. The value 101 (default) indicates success. This may be set to any HTTP status code. For instance a value of 401 indicates an authorization failure.

ResponseHeaders may be set to include additional headers in the response. This is typically used when rejecting a request. For instance when StatusCode is set to 401 you might set ResponseHeaders to "WWW-Authenticate: Basic realm="Secure Realm"" to request authorization from the connecting client.

 
 
Copyright (c) 2021 /n software inc. - All rights reserved.
IPWorks WebSockets 2020 Kotlin Edition - Version 20.0 [Build 7721]