Skip to content

Commit 9cfd4ff

Browse files
authored
doc(Socket): update auto disconnection sample code (#7706)
* fix(MockDisconnectService): 增加 break 防止异常 * refactor: 移除异常捕获处理代码
1 parent 502c2cd commit 9cfd4ff

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/BootstrapBlazor.Server/Services/MockDisconnectService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ private async Task OnDataHandlerAsync(TcpClient client, CancellationToken stoppi
4848
await stream.WriteAsync(Encoding.UTF8.GetBytes(DateTime.Now.ToString("yyyyMMddHHmmss")), stoppingToken);
4949
await Task.Delay(2000, stoppingToken);
5050

51-
// 主动关闭连接
51+
// 主动关闭连接(关闭后 stream 已释放,必须退出循环)
5252
client.Close();
53+
break;
5354
}
5455
catch (OperationCanceledException) { break; }
5556
catch (IOException) { break; }

0 commit comments

Comments
 (0)