c# - NetworkStream.Read() 在短暂不活动后连接到 netcat 实例抛出 IOException?
问题描述
我有一个NetworkStream
连接到远程netcat
实例的对象。一切正常,而我在键盘上打字并且数据在主机之间传输。
$serverStream.Read($bytes, 0, $bytes.Length))
但是,大约 60 秒不活动后,我IOException
在Read()
. 阅读文档告诉我IOException
,当套接字关闭时抛出。
我用netcat
了很多,从来没有经历过它会断开会话。NetworkStream
所以,我猜这个问题与?
如何防止$serverStream.Read()
抛出异常,而只是等到数据可用(保持会话完整)?
网络流:
Exception calling "Read" with "3" argument(s): "Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or establishe
d connection failed because connected host has failed to respond."
At C:\Users\bd6164\Desktop\phishing_revsh.ps1:31 char:9
+ while (($i = $serverStream.Read($bytes, 0, $bytes.Length)) -ne 0) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException
解决方案
网猫
你确定你没有设置超时?
网络流
您可以使用以下行设置网络流的读取超时:
networkStream.ReadTimeout =毫秒;
也许这会帮助你:
推荐阅读
- c# - 如何访问授权用户自定义标签助手
- swift - SQLite.swift 中的过滤和排序查询
- python - 如何计算给定多个父节点的后代?
- php - 使用 oauth2-microsoft 从 Microsoft Graph 检索用户详细信息时出错
- ios - 问题是关于 localhost、Swift URL、NetBeans 和 Xampp
- ios - 返回错误的 UICollectionViewCell 尺寸 - Swift
- python - 获取音频 python ffmpeg
- javascript - 电子邮件输入警告 - 组件正在将文本类型的受控输入更改为不受控制
- ruby-on-rails - 如何判断哪些关联模型未通过我的 ActiveRecord 验证?
- python - 在滚动函数上迭代窗口大小,附加到新的数据框?