The C# .NET SDK currently only supports legacy versions of Nitric prior to v1. This version is maintained for compatibility with existing projects and not recommended for new projects. New projects should be started using a supported SDK (presented automatically using the `nitric new` command) orget in touch to request an update to the latest version.
.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();