- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果Socket
连接成功,我的Java服务器会执行以下操作:
out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
out.write("HELLO");
out.newLine();
out.flush();
这就是我的 C# 客户端所做的事情:
TcpClient tcpClient = new TcpClient("localhost", port);
tcpClient.ReceiveTimeout = 10000;
NetworkStream networkStream = tcpClient.GetStream();
BinaryReader reader = new BinaryReader(networkStream);
reader.ReadString(); // <--- Hangs
tcpClient.Close();
它将卡在ReadString()
上并最终超时。如果你把它改成
reader.Read(); // <--- Returns 72
返回72
,我认为它对应于H
。显然 Java 服务器确实正在发送消息 - 为什么 ReadString() 挂起?
最佳答案
您写入的格式与随后读取的格式不匹配。 BinaryReader.ReadString
的文档说:
Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time.
这与您所写的内容非常不同。
我的猜测是,ReadString
获得了一个大得离谱的“长度”,并且正在尝试读取那么多字节。当然,它们不会被发送。
关于java - 为什么 BinaryReader 卡在 ReadString() 上而不卡在 Read() 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42733013/
我在搜索 BinaryReader.Skip 函数时遇到了这个 feature request on msdn .他说您可以通过使用它来提供自己的 BinaryReader.Skip() 函数。 只看
我有一个基于套接字的应用程序,它使用 BinaryReader 公开接收到的数据客户端的对象。我一直在尝试调试读取器中包含的数据不干净的问题......即我正在读取的缓冲区包含超过新数据大小的旧数据。
Controller : private readonly Dictionary streams; public ActionResult Upload(string qqfile,
我想尝试基本的文件加密和压缩,所以我的第一个问题是 ByteReader 是否是适合该作业的正确阅读器?我的第二个最重要的问题是:使用二进制阅读器时如何循环直到文件末尾?有没有办法像 How read
我需要将 int 数组作为二进制写入输出文件,并在 C++ Linux 的程序中将二进制数据作为 int 读取,类似于 C# 中的 BinaryReader 和 BinaryWriter。我怎样才能做
我正在做家庭作业,但完全卡住了!我想要做的是使用已经定义的输入并使用 saveDataTo() 方法将其保存到文件中,然后使用 readDataFrom() 方法读取输入。 我卡在了第一部分。我不确定
我目前正在编写一个缓存 BaseStream.Position 和 BaseStream.Length 属性的 BinaryReader。这是我目前所拥有的: public class FastBin
我正在使用以下代码序列化数据表中的数据。 var rows = new List>(); 我正在填充 DataTable 中的行并将它们放入字典中。不要问为什么:) using(var fileStr
我正在开发一个解析器来接收 UDP 信息、解析它并存储它。为此,我使用了 BinaryReader,因为它主要是二进制信息。其中一些将是字符串。 MSDN says对于 ReadString() 函数
案例: 再次尝试通过我的 NIC 捕获数据包, 我开发了 2 个扩展用于捕获可变位数 public static string ReadBits ( this BinaryReader Key
当使用 System.IO.BinaryReader 读取二进制文件时,使用任何多字节读取方法时字节顺序似乎不受影响。 BinaryReader br = new BinaryReader(fs, S
我写了下面的方法来使用二进制模式将文件归档到一个文件中: // Compile archive public void CompileArchive(string Fi
我有一个二进制字节数组。在 C# 中,使用 BinaryReader 和 ReadInt32 读取它非常容易(这正是我所需要的)。像这样: reader = new BinaryReader ( ne
我正在继承 BinaryReader 类。 我必须覆盖一些基本方法,例如 ReadUInt16 . 该方法的内部实现是: public virtual ushort ReadUInt16(){
在 C、C++ 中,如果您以二进制方式写入一个整数(例如 fwrite(&someInt,sizeof(int),1,fp))说到文件,您有很多问题需要考虑你想从不同的机器上读取那个整数——例如,字节
BinaryReader 没有 EndOfStream 属性。使用以下代码检查是否已到达流结尾是否安全? reader.BaseStream.Length>reader.BaseStream.Posi
我继承了一些循环通过 BinaryReader 的响应的代码,并且它在一段时间内工作正常(返回 2 个字节),但是客户端需要一段时间才能响应(我假设)并且代码失败进入捕获逻辑。 我找不到任何关于 Re
我想弄清楚我在这里做错了什么。我正在尝试使用 Binary Reader 来轻松地将流中的初始四个字节转换为 Int32 值,该值告诉我其余数据的预期长度。 static void Main(stri
我正在尝试解压缩字节数组并使用二进制读取器将其转换为字符串。执行以下代码时,inStream位置从0变为数组长度,但str始终为空字符串。 BinaryReader br = null; string
我认为 BinaryReader.ReadChars() 方法存在问题。当我在原始套接字 NetworkStream 周围包装 BinaryReader 时,偶尔会出现流损坏,其中正在读取的流不同步。
我是一名优秀的程序员,十分优秀!