.NET - Connection.Close()

Closes a connection to a websocket

using Nitric.Sdk;
var websocket = Nitric.Websocket("public");
websocket.Connection("D28BA458-BFF4-404A").Close();
Nitric.Run();

Parameters

  • Name
    connectionId
    Required
    Required
    Type
    string
    Description

    The ID of the connection which should be closed.

Examples

Close a connection to the websocket on message

using Nitric.Sdk;
using Nitric.Sdk.Function;
class WebsocketMessage
{
public string Status { get; set; }
}
var websocket = Nitric.Websocket("public");
// Broadcast message to all the registered websocket connections
websocket.On(WebsocketEventType.Message, ctx => {
message = ctx.Request.Message<WebsocketMessage>();
if(message.Status == "close")
{
websocket.Connection(ctx.Req.ConnectionId).Close();
}
return ctx;
});
Nitric.Run();
Last updated on Dec 5, 2024