XiaoFeng.Net
2.0.4
See the version list below for details.
dotnet add package XiaoFeng.Net --version 2.0.4
NuGet\Install-Package XiaoFeng.Net -Version 2.0.4
<PackageReference Include="XiaoFeng.Net" Version="2.0.4" />
paket add XiaoFeng.Net --version 2.0.4
#r "nuget: XiaoFeng.Net, 2.0.4"
// Install XiaoFeng.Net as a Cake Addin #addin nuget:?package=XiaoFeng.Net&version=2.0.4 // Install XiaoFeng.Net as a Cake Tool #tool nuget:?package=XiaoFeng.Net&version=2.0.4
XiaoFeng.Net
Nuget:XiaoFeng.Net
QQ群号 | QQ群 | 公众号 |
---|---|---|
748408911 |
源码: https://github.com/zhuovi/XiaoFeng.Net
教程: https://www.yuque.com/fayelf/xiaofeng
XiaoFeng网络库,封装了Socket客户端,服务端,根据当前库可轻松实现订阅,发布等功能。
XiaoFeng.Net
XiaoFeng.Net generator with XiaoFeng.Net.
Install
.NET CLI
$ dotnet add package XiaoFeng.Net --version 2.0.4
Package Manager
PM> Install-Package XiaoFeng.Net --Version 2.0.4
PackageReference
<PackageReference Include="XiaoFeng.Net" Version="2.0.4" />
Paket CLI
> paket add XiaoFeng.Net --version 2.0.4
Script & Interactive
> #r "nuget: XiaoFeng.Net, 2.0.4"
Cake
// Install XiaoFeng.Net as a Cake Addin
#addin nuget:?package=XiaoFeng.Net&version=2.0.4
// Install XiaoFeng.Net as a Cake Tool
#tool nuget:?package=XiaoFeng.Net&version=2.0.4
XiaoFeng.Net Socket操作
服务端实例
//新建一个服务端,同时支持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("取消订阅频道");
作者介绍
- 网址 : http://www.fayelf.com
- QQ : 7092734
- EMail : jacky@fayelf.com
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- XiaoFeng.Core (>= 2.1.0)
-
.NETStandard 2.1
- XiaoFeng.Core (>= 2.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on XiaoFeng.Net:
Package | Downloads |
---|---|
XiaoFeng.Memcached
Memcached中间件,支持.NET框架、.NET内核和.NET标准库,一种非常方便操作的客户端工具。实现了Set,Add,Replace,PrePend,Append,Cas,Get,Gets,Gat,Gats,Delete,Touch,Stats,Stats Items,Stats Slabs,Stats Sizes,Flush_All,Increment,Decrement,线程池功能。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.1.5 | 210 | 10/8/2023 |
3.1.4 | 197 | 9/26/2023 |
3.1.3 | 179 | 8/29/2023 |
3.1.2 | 160 | 8/29/2023 |
3.1.1 | 171 | 8/22/2023 |
3.1.0 | 170 | 8/22/2023 |
3.0.0 | 150 | 8/3/2023 |
2.0.6 | 235 | 3/14/2023 |
2.0.5 | 239 | 3/11/2023 |
2.0.4 | 230 | 3/2/2023 |
2.0.3 | 252 | 3/2/2023 |
2.0.2 | 270 | 2/7/2023 |
2.0.1 | 259 | 2/7/2023 |
2.0.0 | 259 | 12/30/2022 |
修复有新连接时,握手成功后也回调的bug;socket类中增加移出队列时断开客户端连接;优化Socket关闭事件;