Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<PackageReference Include="BootstrapBlazor.RDKit" Version="9.0.2" />
<PackageReference Include="BootstrapBlazor.SignaturePad" Version="9.0.1" />
<PackageReference Include="BootstrapBlazor.SmilesDrawer" Version="9.0.2" />
<PackageReference Include="BootstrapBlazor.Socket" Version="9.0.10" />
<PackageReference Include="BootstrapBlazor.Socket" Version="9.0.11" />
<PackageReference Include="BootstrapBlazor.Sortable" Version="9.0.3" />
<PackageReference Include="BootstrapBlazor.Splitting" Version="9.0.3" />
<PackageReference Include="BootstrapBlazor.SvgEditor" Version="9.0.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
options.LocalEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
});</Pre>
<ul class="ul-demo">
<li>点击 <b>连接</b> 按钮后通过 <code>ITcpSocketFactory</code> 服务实例创建的 <code>ITcpSocketClient</code> 对象连接到网站模拟 <code>TcpServer</code></li>
<li>点击 <b>连接</b> 按钮后通过 <code>ITcpSocketFactory</code> 服务实例(<a href="/socket-factory" target="_blank">传送门</a>)创建的 <code>ITcpSocketClient</code> 对象连接到网站模拟 <code>TcpServer</code></li>
<li>点击 <b>断开</b> 按钮调用 <code>CloseAsync</code> 方法断开 Socket 连接</li>
<li>点击 <b>发送</b> 按钮调用 <code>SendAsync</code> 方法发送请求数据</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
Name="Normal" ShowCode="false">
<p>本例中连接一个模拟时间同步服务,每间隔 10s 自动发送服务器时间戳,连接后无需发送任何数据即可持续收到时间戳数据</p>
<ul class="ul-demo">
<li>点击 <b>连接</b> 按钮后通过 <code>ITcpSocketFactory</code> 服务实例创建的 <code>ITcpSocketClient</code> 对象连接到网站模拟 <code>TcpServer</code></li>
<li>点击 <b>连接</b> 按钮后通过 <code>ITcpSocketFactory</code> 服务实例(<a href="/socket-factory" target="_blank">传送门</a>)创建的 <code>ITcpSocketClient</code> 对象连接到网站模拟 <code>TcpServer</code></li>
<li>点击 <b>断开</b> 按钮调用 <code>CloseAsync</code> 方法断开 Socket 连接</li>
</ul>
<p>使用 <code>ReceivedCallBack</code> 委托获得接收到的数据,可通过 <code>+=</code> 方法支持多个客户端接收数据</p>
<Pre>_client.ReceivedCallBack += OnReceivedAsync;</Pre>
<p>特别注意页面需要继承 <code>IDisposable</code> 或者 <code>IAsyncDisposable</code> 接口,在 <code>Dispose</code> 或者 <code>DisposeAsync</code> 中移除委托</p>
<p>特别注意如果当前页面对 <code>ISocketClient</code> 实例不销毁时需要继承 <code>IDisposable</code> 或者 <code>IAsyncDisposable</code> 接口,在 <code>Dispose</code> 或者 <code>DisposeAsync</code> 中移除委托,以防止内存泄露</p>
<Pre>private void Dispose(bool disposing)
{
if (disposing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ class MockEntity
{
return new Foo() { Id = data.Span[0], Name = name };
}
}</Pre>
<p>此处返回值会与参数 <code>Type = typeof(Foo)</code> 做数据合规检查,如果返回值无法转换为指定 <code>Type</code> 时不进行赋值操作,代码逻辑如下</p>
<Pre>var attr = p.GetCustomAttribute&lt;DataPropertyConverterAttribute&gt;(false) ?? GetPropertyConverterAttribute(p);
if (attr is { Type: not null })
{
var value = attr.ConvertTo(data);
var valueType = value?.GetType();
if (p.PropertyType.IsAssignableFrom(valueType))
{
p.SetValue(entity, value);
}
}</Pre>
<p>更多技术细节可以参考以上内置提供的转换器源码</p>
</DemoBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
Name="Normal" ShowCode="false">
<p>本例中连接一个模拟时间同步服务,采用一发一收的方式进行通讯,连接后发送查询电文,接收到服务器端响应时间戳电文数据</p>
<ul class="ul-demo">
<li>点击 <b>连接</b> 按钮后通过 <code>ITcpSocketFactory</code> 服务实例创建的 <code>ITcpSocketClient</code> 对象连接到网站模拟 <code>TcpServer</code></li>
<li>点击 <b>连接</b> 按钮后通过 <code>ITcpSocketFactory</code> 服务实例(<a href="/socket-factory" target="_blank">传送门</a>)创建的 <code>ITcpSocketClient</code> 对象连接到网站模拟 <code>TcpServer</code></li>
<li>点击 <b>断开</b> 按钮调用 <code>CloseAsync</code> 方法断开 Socket 连接</li>
<li>点击 <b>发送</b> 按钮调用 <code>SendAsync</code> 方法发送请求数据</li>
</ul>
<p>默认已经开启了自动接收,需要通过配置显式设置为手动接收</p>
<Pre>_client = TcpSocketFactory.GetOrCreate("demo-manual-receive", options =>
{
options.LocalEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
options.IsAutoReceive = false;
});</Pre>
<p>使用 <code>ReceiveAsync</code> 方法主动接收数据</p>
<div class="row form-inline g-3">
<div class="col-12 col-sm-6">
Expand Down
Loading