我将以下代码作为 TCP/IP 服务器的一部分。该程序运行良好,但我注意到当 Server
断开连接时,在 Client
上抛出 System.IO.IOException 错误。 (我实际上是在断开客户端连接。)
Private Sub ReadAllClient()
Try
RaiseEvent getMessage(New StreamReader(listClient.GetStream).ReadLine)
listClient.GetStream.BeginRead(New Byte() {0}, 0, 0, New AsyncCallback(AddressOf ReadAllClient), Nothing)
Catch ex As Exception
RaiseEvent clientLogout(Me)
End Try
End Sub
(编辑:错误消息详细信息)
System.IO.IOException: 'Unable to read data from the transport
connection: An established connection was aborted by the software in
your host machine.'
此错误通常不是 VS 2017 的一部分,只是将其用于查找原因,这就是 Try/Catch 语句。 (Catch 部分肯定是有效的……但错误正在被抛出。)
我应该担心抛出这个异常吗?或者忽略它是否足够安全?