Skip to content

Commit 6cbad20

Browse files
committed
refactor: 更新接收数据示例代码
1 parent 219008b commit 6cbad20

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/BootstrapBlazor.Server/Components/Samples/Sockets/Receives.razor.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace BootstrapBlazor.Server.Components.Samples.Sockets;
1010
/// <summary>
1111
/// 接收电文示例
1212
/// </summary>
13-
public partial class Receives : ComponentBase, IDisposable
13+
public partial class Receives : IDisposable
1414
{
1515
[Inject, NotNull]
1616
private ITcpSocketFactory? TcpSocketFactory { get; set; }
@@ -19,6 +19,8 @@ public partial class Receives : ComponentBase, IDisposable
1919

2020
private List<ConsoleMessageItem> _items = [];
2121

22+
private readonly IPEndPoint _serverEndPoint = new(IPAddress.Loopback, 8800);
23+
2224
/// <summary>
2325
/// <inheritdoc/>
2426
/// </summary>
@@ -27,7 +29,7 @@ protected override void OnInitialized()
2729
base.OnInitialized();
2830

2931
// 从服务中获取 Socket 实例
30-
_client = TcpSocketFactory.GetOrCreate("bb", options =>
32+
_client = TcpSocketFactory.GetOrCreate("demo-receive", options =>
3133
{
3234
options.LocalEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
3335
});
@@ -38,7 +40,7 @@ private async Task OnConnectAsync()
3840
{
3941
if (_client is { IsConnected: false })
4042
{
41-
await _client.ConnectAsync("127.0.0.1", 8800, CancellationToken.None);
43+
await _client.ConnectAsync(_serverEndPoint, CancellationToken.None);
4244
}
4345
}
4446

0 commit comments

Comments
 (0)