-
Notifications
You must be signed in to change notification settings - Fork 3
Basic configuration of WebSocketServer
Here's how to use WebSocketRouteOption
How to configure WebSocket Server:
Fully qualified class name Cyaim.WebSocketServer.Infrastructure.Configures
This property is shared within a single WebSocket Option instance and is primarily obtained internally through DI containers to retrieve key objects. It is automatically set when calling UseWebSocket Server
This property is generally null, call WebSocketRouteMiddlewareExtensions After the GetWebSocket Address() method, it will be set, usually indicating where the WebSocketServer is listening.
This property is a comparison option, usually configured as the current dependency injection container in the Configuring WebSocket Route () method when configuring the Service (other requirements can be configured themselves). Mainly used to create the class to which the method marked by the hit WebSocket endpoint belongs, using DI container injected constructor parameter objects.
When the endpoint marked by the WebSocket feature is hit, HttpContext and WebSocket object will be injected into the class properties to which the endpoint belongs, with default property names of WebSocketHttpContext and WebSocketClient, respectively.
You can modify attribute names as needed or remove attributes from the class
This property is used to define the WebSocket connection channel. Key represents the connection path, and Value is the entry method of the handler.
WebSocketServer will fully transmit sub protocol information
You can create your own handler to handle WebSocket connections by implementing the IWebSocketHandler interface.
This attribute stores the basic information read from the assembly pointed to by the WatchAssemblyPath attribute for WebSocket Server to run. If your application includes dynamic code generation, to take immediate effect, you need to update the objects in that property.
This attribute indicates the assembly path to which the endpoint to be listened to belongs. Default is the executable process in the application domain, or the first executable file executed by the system.
When calling the WebSocketRouteServiceCollectionExtensions.ConfigureWebSocketRoute() method, automatically load and read the data required for WebSocket Server to run and convert it into WatchAssemblyContext object.
Assembly prefix for Watch [WebSocket],Default:The Controllers folder of this assembly.
Setting this property means that you can freely decide the path containing the class to which the endpoint belongs. For example, in the example, it defaults to Cyanim WebSocketServer.Example.Controllers, You can modify it to Cyaim at will WebSocketServer.Example.WebSocketEndPoints.
This attribute is true when the value of the environment variable ASPNETCORE_ENVIRONMENT is Development. When this attribute is true, the response body will contain error information.
This attribute represents the upper limit of the volume of a single client request received, counted in bytes. Exceeding the upper limit, this request will end directly.
This property indicates whether multiple connections are allowed for one ConnectId (ConnectId refers to the Id obtained from HttpContext.Connection. Id).Default to true.
This attribute represents the maximum connection limit, which will reject connections if it exceeds the indicated value, but it will not override Kestrel's configuration.
How to configure Kestrel? Please read:https://learn.microsoft.com/zh-cn/aspnet/core/fundamentals/servers/kestrel/options?view=aspnetcore-8.0#maximum-client-connections
Indicate whether to perform synchronous processing of requests. If true, the target of each websocket request will wait for processing to complete (ensuring response order). If parallel processing of the target is required for websocket requests, false. Default to false.
This is at the connection level
Limit the maximum number of tasks forwarded per connection. If it is null, it means unrestricted.
This is at the endpoint level
Limit the maximum number of tasks forwarded by each endpoint. Key:EndPoint name, Value: SemaphoreSlim Object When waiting for the endpoint task to complete, SemanticSlim will be automatically called WaitAsync().
- BeforeConnectionEvent
delegate Task<bool> BeforeConnectionHandler(HttpContext context, WebSocketRouteOption webSocketOptions, string channel, ILogger<WebSocketRouteMiddleware> logger)The prototype of the event delegation is as above. context is the HttpContext object when entering middleware. channel is equivalent to context.Request.Path.
Returning false in the event will prevent the establishment of a connection.
- DisconnectedEvent
delegate Task DisconnectedHandler(HttpContext context, WebSocketRouteOption webSocketOptions, string channel, ILogger<WebSocketRouteMiddleware> logger);Similar to BeforeConnectionEvent.
The default Json configuration used by the processing program when handling requests.
new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
WriteIndented = false
}The default Json configuration used by the processing program to handle responses
new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
WriteIndented = false
}