Skip to content

Web socket listener ​

Embedded WebSocket server: accepts WebSocket connections on a port and path, emits every received message and sends messages back to a connected client. Use it for push or chat style endpoints; reply with the listener's Input pin or a Web socket response component.

Pins ​

PinKindTypesDescription
StartstartStarts the server. Called by the system at flow start when unconnected.
OutputoutputViaducta.Plugins.Http.Types.WebSocketMessageCalled for every message received from any client.
InputinputViaducta.Plugins.Http.Types.WebSocketMessage, Viaducta.Plugins.TextPlugin.Types.TextRecordMessage to send to a client.
AuthenticatecontinueViaducta.Plugins.Http.Types.WebHttpRequestCalled before a connection is accepted. See Notes.

Configuration ​

FieldTypeDefaultDescription
ListenUrllistener URLRequired. http://localhost:<port>/<path> (private) or http://0.0.0.0:<port>/<path> (public), e.g. http://0.0.0.0:9001/ws. Clients connect with ws://host:9001/ws.
MaxParallelRequestsinteger (1-4096)1024Max requests processed in parallel. Further requests wait for a free slot until the caller gives up; open (keep-alive) connections are not limited.
MaxRequestBodySizeinteger0Max request body size, 0 = unlimited.
Timeoutinteger60000Ignored.
KeepAliveTimeoutinteger130HTTP keep-alive timeout in seconds.
MaxRequestHeaderCountinteger100Max number of request headers.
UseSslbooleanfalsetrue: TLS (wss://).
SslProtocoldropdown: 0 None, 12 Ssl2, 48 Ssl3, 192 Tls, 240 Default, 768 Tls11, 3072 Tls12, 12288 Tls130Allowed protocol(s) when UseSsl.
ServerCertificatecertificateName of a certificate object in the repository, used when UseSsl.

Behaviour ​

  • Non-WebSocket requests get 400. If Authenticate is connected and raises an error, the handshake is answered with 401 and the error text; otherwise the connection is accepted and gets a unique session id.
  • Each complete message (max 1 MB, larger messages close the connection) is emitted on Output as WebSocketMessage with SessionId, MessageType (0 text, 1 binary), ContentByte and ContentString (UTF-8). The WebSocketListener metadata carries the SessionId. Messages of one connection are processed one after another.
  • Input: a TextRecord is sent as text to the session in the metadata; a WebSocketMessage is sent to its own SessionId (ContentByte wins over ContentString). An unknown session id raises an error.
  • With no Output connection, clients are disconnected with a message. The plugin keeps the flow running and closes all connections when the flow stops.
  • Port sharing with Http listeners follows the same rules as the Http listener (same SSL/certificate/visibility, different paths under the same first segment).

Notes ​

  • Authenticate receives the raw ASP.NET request object, not a WebHttpRequest, and empty metadata, so Http authentification connected there does not work as with the Http listener; test any authentication branch carefully.
  • If an Http listener on the same port starts first, WebSocket support is not enabled on that shared server and upgrades fail; use a separate port.
  • Timeout is not used. With a single listener on a port, every path is accepted.
  • To push to a client later (not as a reply), keep its SessionId and send a WebSocketMessage with that id to Input.

Example ​

json
{ "ListenUrl": "http://0.0.0.0:9001/ws" }

Web socket listener → Script (build reply) → Web socket response

Viaducta documentation