File tree Expand file tree Collapse file tree 5 files changed +22
-5
lines changed
src/BootstrapBlazor.Server
Components/Samples/Sockets Expand file tree Collapse file tree 5 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 68
68
<PackageReference Include =" BootstrapBlazor.RDKit" Version =" 9.0.2" />
69
69
<PackageReference Include =" BootstrapBlazor.SignaturePad" Version =" 9.0.1" />
70
70
<PackageReference Include =" BootstrapBlazor.SmilesDrawer" Version =" 9.0.2" />
71
- <PackageReference Include =" BootstrapBlazor.Socket" Version =" 9.0.10 " />
71
+ <PackageReference Include =" BootstrapBlazor.Socket" Version =" 9.0.11 " />
72
72
<PackageReference Include =" BootstrapBlazor.Sortable" Version =" 9.0.3" />
73
73
<PackageReference Include =" BootstrapBlazor.Splitting" Version =" 9.0.3" />
74
74
<PackageReference Include =" BootstrapBlazor.SvgEditor" Version =" 9.0.4" />
Original file line number Diff line number Diff line change 25
25
options .LocalEndPoint = new IPEndPoint (IPAddress .Loopback , 0 );
26
26
} );</Pre >
27
27
<ul class =" ul-demo" >
28
- <li >点击 <b >连接</b > 按钮后通过 <code >ITcpSocketFactory</code > 服务实例创建的 <code >ITcpSocketClient</code > 对象连接到网站模拟 <code >TcpServer</code ></li >
28
+ <li >点击 <b >连接</b > 按钮后通过 <code >ITcpSocketFactory</code > 服务实例(< a href = " /socket-factory " target = " _blank " >传送门</ a >)创建的 <code >ITcpSocketClient</code > 对象连接到网站模拟 <code >TcpServer</code ></li >
29
29
<li >点击 <b >断开</b > 按钮调用 <code >CloseAsync</code > 方法断开 Socket 连接</li >
30
30
<li >点击 <b >发送</b > 按钮调用 <code >SendAsync</code > 方法发送请求数据</li >
31
31
</ul >
Original file line number Diff line number Diff line change 11
11
Name =" Normal" ShowCode =" false" >
12
12
<p >本例中连接一个模拟时间同步服务,每间隔 10s 自动发送服务器时间戳,连接后无需发送任何数据即可持续收到时间戳数据</p >
13
13
<ul class =" ul-demo" >
14
- <li >点击 <b >连接</b > 按钮后通过 <code >ITcpSocketFactory</code > 服务实例创建的 <code >ITcpSocketClient</code > 对象连接到网站模拟 <code >TcpServer</code ></li >
14
+ <li >点击 <b >连接</b > 按钮后通过 <code >ITcpSocketFactory</code > 服务实例(< a href = " /socket-factory " target = " _blank " >传送门</ a >)创建的 <code >ITcpSocketClient</code > 对象连接到网站模拟 <code >TcpServer</code ></li >
15
15
<li >点击 <b >断开</b > 按钮调用 <code >CloseAsync</code > 方法断开 Socket 连接</li >
16
16
</ul >
17
17
<p >使用 <code >ReceivedCallBack</code > 委托获得接收到的数据,可通过 <code >+=</code > 方法支持多个客户端接收数据</p >
18
18
<Pre >_client.ReceivedCallBack += OnReceivedAsync;</Pre >
19
- <p >特别注意页面需要继承 <code >IDisposable</code > 或者 <code >IAsyncDisposable</code > 接口,在 <code >Dispose</code > 或者 <code >DisposeAsync</code > 中移除委托</p >
19
+ <p >特别注意如果当前页面对 <code >ISocketClient</ code > 实例不销毁时需要继承 < code > IDisposable</code > 或者 <code >IAsyncDisposable</code > 接口,在 <code >Dispose</code > 或者 <code >DisposeAsync</code > 中移除委托,以防止内存泄露 </p >
20
20
<Pre >private void Dispose(bool disposing)
21
21
{
22
22
if (disposing )
Original file line number Diff line number Diff line change @@ -82,6 +82,17 @@ class MockEntity
82
82
{
83
83
return new Foo () { Id = data .Span [0 ], Name = name };
84
84
}
85
+ } </Pre >
86
+ <p >此处返回值会与参数 <code >Type = typeof(Foo)</code > 做数据合规检查,如果返回值无法转换为指定 <code >Type</code > 时不进行赋值操作,代码逻辑如下</p >
87
+ <Pre >var attr = p.GetCustomAttribute< ; DataPropertyConverterAttribute> ; (false) ?? GetPropertyConverterAttribute(p);
88
+ if (attr is { Type : not null } )
89
+ {
90
+ var value = attr .ConvertTo (data );
91
+ var valueType = value ? .GetType ();
92
+ if (p .PropertyType .IsAssignableFrom (valueType ))
93
+ {
94
+ p .SetValue (entity , value );
95
+ }
85
96
} </Pre >
86
97
<p >更多技术细节可以参考以上内置提供的转换器源码</p >
87
98
</DemoBlock >
Original file line number Diff line number Diff line change 11
11
Name =" Normal" ShowCode =" false" >
12
12
<p >本例中连接一个模拟时间同步服务,采用一发一收的方式进行通讯,连接后发送查询电文,接收到服务器端响应时间戳电文数据</p >
13
13
<ul class =" ul-demo" >
14
- <li >点击 <b >连接</b > 按钮后通过 <code >ITcpSocketFactory</code > 服务实例创建的 <code >ITcpSocketClient</code > 对象连接到网站模拟 <code >TcpServer</code ></li >
14
+ <li >点击 <b >连接</b > 按钮后通过 <code >ITcpSocketFactory</code > 服务实例(< a href = " /socket-factory " target = " _blank " >传送门</ a >)创建的 <code >ITcpSocketClient</code > 对象连接到网站模拟 <code >TcpServer</code ></li >
15
15
<li >点击 <b >断开</b > 按钮调用 <code >CloseAsync</code > 方法断开 Socket 连接</li >
16
16
<li >点击 <b >发送</b > 按钮调用 <code >SendAsync</code > 方法发送请求数据</li >
17
17
</ul >
18
+ <p >默认已经开启了自动接收,需要通过配置显式设置为手动接收</p >
19
+ <Pre >_client = TcpSocketFactory.GetOrCreate("demo-manual-receive", options =>
20
+ {
21
+ options .LocalEndPoint = new IPEndPoint (IPAddress .Loopback , 0 );
22
+ options .IsAutoReceive = false ;
23
+ } );</Pre >
18
24
<p >使用 <code >ReceiveAsync</code > 方法主动接收数据</p >
19
25
<div class =" row form-inline g-3" >
20
26
<div class =" col-12 col-sm-6" >
You can’t perform that action at this time.
0 commit comments