
Nuget: XiaoFeng.Net
| QQ Group Number | QQ Group | Official account |
|---|---|---|
| 748408911 | ![]() | ![]() |
Source code: https://github.com/zhuovi/XiaoFeng.Net
Tutorial: https://www.yuque.com/fayelf/xiaofeng
XiaoFeng network library encapsulates Socket client and server, and can easily implement subscription, publishing and other functions based on the current library.
XiaoFeng.Net generator with XiaoFeng.Net.
.NET CLI
$ dotnet add package XiaoFeng.Net --version 3.1.5
Package Manager
PM> Install-Package XiaoFeng.Net --Version 3.1.5
PackageReference
<PackageReference Include="XiaoFeng.Net" Version="3.1.5" />
Paket CLI
> paket add XiaoFeng.Net --version 3.1.5
Script & Interactive
> #r "nuget: XiaoFeng.Net, 3.1.5"
Cake
// Install XiaoFeng.Net as a Cake Addin
#addin nuget:?package=XiaoFeng.Net&version=3.1.5
// Install XiaoFeng.Net as a Cake Tool
#tool nuget:?package=XiaoFeng.Net&version=3.1.5
1. Fix the bug when SocketClient is connected to DNS;
1. Optimize the judgment of the minimum and maximum value of NetworkDelay in SocketClient;
2. Optimize the bug in SocketClient where the host is connected to IP;
3. Optimize XiaoFeng.Net.WebSocketClient request header;
4. Optimize network client;
1. Optimize the bugs that occasionally refuse connections when the server receives websocket clients when the network delay time is used.
2.SocketServer and SocketClient add NetworkDelay network delay attribute;
3. Optimize the AcceptTcpClient method in SocketServer;
1. Optimize SocketClient, bugs that are not unpacked on the websocket client;
2. Optimize the bug where the SocketClient is only called on the OnMessage event but not the OnMessageByte event for the first connection;
3.SocketClient increases the last communication time of LastMessageTime and the ConnectedTime connection time;
4. Optimize the identification of whether the client is WebSocket or Socket;
5.SocketClient connection method adds the return type;
1. Fixed the problem that the server cannot receive the message when postman is constantly sending messages under SSL;
1. Add the property WebSocketRequest in WebSocketClient to the client request information;
2. WebSocketClient adds the start-transfer data WebSocketRequestOptions;
3. Optimize Socket network library annotations;
4. Fixed the bug where SocketServer sends a new connection callback every time he receives a message;
1. Rewrite the Socket library, SocketServer, WebSocketServer, SocketClient, WebSocketClient;
| Namespace | Class library | Open source status | illustrate | Includes functions |
|---|---|---|---|---|
| XiaoFeng.Prototype | XiaoFeng.Core | Extended library | ToCase type conversion ToTimestamp,ToTimestamps Time to Timestamp GetBasePath Gets the absolute path of the file, supports Linux and Windows GetFileName Gets the file name GetMatch, GetMatches, GetMatchs, IsMatch, ReplacePatten, RemovePattern Regular Expression Operation | |
| XiaoFeng.Net | XiaoFeng.Net | Network library | XiaoFeng network library encapsulates Socket client and server (Socket, WebSocket), and can easily implement subscription, publishing and other functions based on the current library. | |
| XiaoFeng.Http | XiaoFeng.Core | Simulation request library | Simulate network requests | |
| XiaoFeng.Data | XiaoFeng.Core | Database operation library | Support dozens of databases such as SQLSERVER, MYSQL, ORACLE, Dameng, SQLITE, ACCESS, OLEDB, ODBC, etc. | |
| XiaoFeng.Cache | XiaoFeng.Core | Cache library | Memory Cache, Redis, MemcachedCache, MemoryCache, FileCache Cache | |
| XiaoFeng.Config | XiaoFeng.Core | Configuration File Library | Automatically generate configuration files by creating models, which can be in xml, json, ini file format | |
| XiaoFeng.Cryptography | XiaoFeng.Core | Encryption algorithm library | AES, DES, RSA, MD5, DES3, SHA, HMAC, RC4 encryption algorithm | |
| XiaoFeng.Excel | XiaoFeng.Excel | Excel operation library | Excel operations, create excel, edit excel, read excel content, borders, fonts, styles and other functions | |
| XiaoFeng.Ftp | XiaoFeng.Ftp | FTP request library | FTP Client | |
| XiaoFeng.IO | XiaoFeng.Core | File operation library | File read and write operations | |
| XiaoFeng.Json | XiaoFeng.Core | Json serialization, deserialization library | Json serialization, deserialization library | |
| XiaoFeng.Xml | XiaoFeng.Core | Xml serialization, deserialization library | Xml serialization, deserialization library | |
| XiaoFeng.Log | XiaoFeng.Core | Log library | Write log files, databases | |
| XiaoFeng.Memcached | XiaoFeng.Memcached | Memcached cache library | Memcached middleware supports .NET framework, .NET kernel and .NET standard library, a very convenient client tool. Implement the functions of Set, Add, Replace, PrePend, Append, Cas, Get, Gets, Gat, Gats, Delete, Touch, Stats, Stats Items, Stats Slabs, Stats Sizes, Flush_All, Increment, Decrement, and thread pooling. | |
| XiaoFeng.Redis | XiaoFeng.Redis | Redis cache library | Redis middleware supports .NET framework, .NET kernel and .NET standard library, a very convenient client tool. Implements the functions of Hash, Key, String, ZSet, Stream, Log, List, subscription and publishing, and thread pooling; | |
| XiaoFeng.Threading | XiaoFeng.Core | Thread library | Thread tasks, thread queues | |
| XiaoFeng.Mvc | XiaoFeng.Mvc | Low-code WEB development framework | .net core basic class, rapid development of CMS framework, real low-code platform, own role permissions, WebAPI platform, background management, hostable service run commands: application.exe install service name service description, command and delete delete start start stop stop. | |
| XiaoFeng.Proxy | XiaoFeng.Proxy | Agent library | Under development | |
| XiaoFeng.TDengine | XiaoFeng.TDengine | TDengine Client | Under development | |
| XiaoFeng.GB28181 | XiaoFeng.GB28181 | Video surveillance library, SIP library, GB28181 protocol | Under development | |
| XiaoFeng.Onvif | XiaoFeng.Onvif | Video surveillance library Onvif protocol | XiaoFeng.Onvif uses C# to encapsulate Onvif's commonly used interfaces, devices, media, gimbals and other functions based on the .NET platform. It refuses the WCF service to reference dynamic proxy to generate wsdl-like files, and uses native XML extension markup language to encapsulate parameters. All data flows are controllable. |
//新建一个服务端,同时支持websocket,socket客户端连接
var server = new NetServer < ServerSession > ( 8088 )
{
//是否启用ping
IsPing = true ,
//是否启用新行
IsNewLine = true ,
//传输编码
Encoding = System . Text . Encoding . UTF8 ,
//认证 认证不过则直接断开
SocketAuth = s =>
{
//判断 客户端是否符合认证,不符合则直接返回false即可
return true ;
}
} ;
server . OnStart += ( s , e ) =>
{
//服务端启动事件
Console . WriteLine ( $ "启动!- { DateTime . Now : yyyy-MM-dd HH:mm:ss.fffffff } " ) ;
} ;
server . OnNewConnection += ( s , e ) =>
{
//客户端新连接事件
Console . WriteLine ( $ "新连接- { DateTime . Now : yyyy-MM-dd HH:mm:ss.fffffff } " ) ;
//给当前客户端设置一个频道名 为后边按频道名发送作准备
//一个客户端可以订阅多个频道
//websocket可以从头里面获取标识
//如果非websocket 可以从消息里设置频道消息
if ( s . Headers . IndexOf ( "Channel:a" ) > 0 )
s . AddChannel ( "a" ) ;
else
s . AddChannel ( "b" ) ;
} ;
server . OnDisconnected += ( s , e ) =>
{
//客户端断开连接事件
Console . WriteLine ( $ "断开连接!- { DateTime . Now : yyyy-MM-dd HH:mm:ss.fffffff } " ) ;
} ;
server . OnMessage += ( s , m , e ) =>
{
//接收消息事件
if ( m . IndexOf ( "Channel:a" ) > 0 )
{
s . AddChannel ( "a" ) ;
return ;
}
else if ( m . IndexOf ( "Channel:b" ) > 0 )
{
s . AddChannel ( "b" ) ;
return ;
}
Console . WriteLine ( $ "消息- { m } - { DateTime . Now : yyyy-MM-dd HH:mm:ss.fffffff } " ) ;
//把当前消息发送到频道名为a的所有客户端
server . Send ( "a" , Encoding . UTF8 . GetBytes ( "消息" ) ) ;
//回复当前客户端消息
s . Send ( "消息" ) ;
//发送消息给所有客户端
server . Send ( "消息" ) ;
} ;
server . OnMessageByte += ( session , message , e ) =>
{
//接收消息事件
session . Send ( "回复客户端消息" ) ;
} ;
server . OnError += ( s , e ) =>
{
//服务端出错事件
Console . WriteLine ( $ "出错- { e . Message } - { DateTime . Now : yyyy-MM-dd HH:mm:ss.fffffff } " ) ;
} ;
server . OnClientError += ( session , e ) =>
{
//客户端出错事件
} ;
server . OnError += ( session , e ) =>
{
//服务端出错事件
} ;
server . OnStop += ( socket , e ) =>
{
//服务端停止事件
} ;
server . Start ( ) ;
//添加黑名单
server . AddIpBlack ( "10.10.10.10" ) ;
//移除黑名单
server . RemoveIpBlack ( "10.10.10.10" ) ;
//清空黑名单
server . ClearIpBlack ( ) ;
//断开所有客户端
server . ClearQueue ( ) ;
//在线客户端列表 复制出来的
var clients = server . GetData ( ) ;
//在线客户端列表 原列表
var clients1 = server . ConnectionSocketList ; var client = new XiaoFeng . Net . NetClient < XiaoFeng . Net . ClientSession > ( "127.0.0.1" , 8888 ) ;
client . OnStart += ( socket , e ) =>
{
//启动消息
} ;
client . OnClose += ( socket , e ) =>
{
//关闭消息
} ;
client . OnDisconnected += ( session , e ) => {
//断开连接消息
} ;
client . OnError += ( socket , e ) =>
{
//出错消息
} ;
client . OnMessageByte += ( session , message , e ) =>
{
//接收信息
} ;
//启动客户端
client . Start ( ) ;
client . Send ( "发送消息" ) ;
client . Subscribe ( "订阅频道" ) ;
client . UnSubscribe ( "取消订阅频道" ) ;