You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2025 WenJY 保留所有权利。
* CLR版本: 4.0.30319.42000
* 机器名称: Mr.Wen's MacBook Pro
* 命名空间: Sln.Rfid.Business
* 唯一标识: 71B66923-4C77-4F26-8922-8F44566AE103
*
* 创建者: WenJY
* 电子邮箱:
* 创建时间: 2025-11-26 20:19:17
* 版本: V1.0.0
* 描述:
*
*--------------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本: V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System ;
using System.Collections.Generic ;
using System.Linq ;
using Fleck ;
using Sln.Rfid.Serilog ;
namespace Sln.Rfid.Business
{
public class WebSocketBusiness
{
private List < IWebSocketConnection > allSockets = new List < IWebSocketConnection > ( ) ;
private readonly SerilogHelper _logger ;
public WebSocketBusiness ( SerilogHelper serilogHelper )
{
_logger = serilogHelper ;
}
public void Init ( )
{
var server = new Fleck . WebSocketServer ( $"ws://0.0.0.0:7181" ) ;
server . Start ( socket = >
{
socket . OnOpen = ( ) = >
{
var data = socket . ConnectionInfo ;
_logger . Info ( "WebSocket Open!" ) ;
allSockets . Add ( socket ) ;
} ;
socket . OnClose = ( ) = >
{
_logger . Info ( "WebSocket Close!" ) ;
allSockets . Remove ( socket ) ;
} ;
socket . OnMessage = message = >
{
//ReceivedMessageRequestInfoEvent?.Invoke(socket, message);
} ;
} ) ;
}
public void PushMsg ( string msg )
{
try
{
foreach ( var socket in allSockets . ToList ( ) )
{
socket . Send ( msg ) ;
_logger . Info ( $"WebSocket推送信息:{msg}" ) ;
}
}
catch ( Exception ex )
{
_logger . Info ( $"WebSocket推送信息异常:{ex.Message}" ) ;
}
}
}
}