Skip to content

Commit 4751dff

Browse files
committed
refactor: 更新自动接收逻辑增加已连接逻辑判断
1 parent d6d37a5 commit 4751dff

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/BootstrapBlazor/Services/TcpSocket/DefaultTcpSocketClient.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ public override async ValueTask<bool> ConnectAsync(IPEndPoint endPoint, Cancella
4444
}
4545
await _client.ConnectAsync(endPoint, connectionToken);
4646

47-
// 设置本地以及远端端点信息
48-
LocalEndPoint = (IPEndPoint)_client.Client.LocalEndPoint!;
49-
_remoteEndPoint = endPoint;
50-
51-
if (IsAutoReceive)
47+
if (_client.Connected)
5248
{
53-
_ = Task.Run(AutoReceiveAsync);
49+
// 设置本地端点信息
50+
if (_client.Client.LocalEndPoint is IPEndPoint local)
51+
{
52+
LocalEndPoint = local;
53+
}
54+
if (IsAutoReceive)
55+
{
56+
_ = Task.Run(AutoReceiveAsync);
57+
}
5458
}
5559
ret = _client.Connected;
5660
}

0 commit comments

Comments
 (0)