- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 ByteBuf 通过 netty 发送字符串。首先,我将字符串转换为字节数组,如下所示:
byteBuf.writeInt(this.serverName.length());
byteBuf.writeInt(this.ipAdress.length());
byteBuf.writeBytes(this.serverName.getBytes(StandardCharsets.UTF_8));
byteBuf.writeBytes(this.ipAdress.getBytes(StandardCharsets.UTF_8));
这很好用,但我不知道如何读取字节以将它们转换回字符串?
我尝试过类似的事情:
int snLen = byteBuf.readInt();
int ipLen = byteBuf.readInt();
byte[] bytes = new byte[byteBuf.readableBytes()];
System.out.println(byteBuf.readBytes(bytes).readByte());
this.ipAdress = "";
一定有什么东西可以取回字节。您可以从字符串发送字节,但最后无法取回字节?似乎有一个方法,但我不知道如何做到这一点。
我希望你们中的任何人都可以帮助我。提前致谢! :)
最佳答案
在 netty 4.1 中你可以使用:
byteBuf.writeCharSequence(...)
byteBuf.readCharSequence(...)
关于java - 使用 byte[] 数组通过 ByteBuf 读写字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45762752/
概述 网络数据的基本单位总是字节,Java NIO 提供了 ByteBuffer 作为它的字节容器,但这个类的使用过于复杂。Netty 的 ByteBuf 具有卓越的功能性和灵活性,可以作为 Byte
你好,我写了一个简单的tcp发送数据到netty服务器演示,这里是代码: 客户端.java package chat; import java.io.ByteArrayOutputStream; im
当我从服务器向客户端或反之发送数据包时,我需要确保该数据包是合法的,我检查接收到的数据包的大小,如果接收到的数据包的大小与它的大小相同,则进行匹配应该是。 每个数据包都是一个操作码,操作码用于知道它是
我的计划是制定如下所示的消息协议(protocol): MessageLength:消息总长度的整数 MessageID:具有自动递增标识符的整数 MessageType:带有消息类型的整数(enum
我是 Netty 的新手。文件传输有一个问题让我困惑了好几天。我想从客户端向服务器发送图像文件。 下面的代码是可执行的。但是只有我强行关闭服务器才能正常打开接收到的图片文件。否则,它会显示“您似乎没有
我正在学习 Netty 实战。 在5.2.2 ByteBuf usage patterns一章中,有一段代码让我很困惑。如下所示。 ByteBuf heapBuf = ... if (heapBuf.
我每个人。 我问你是因为我的Netty解码器中的ByteBuf有问题。 我想解码通过服务器到达的消息,但 ByteBuf 无法像我希望的那样工作。 问题是 ByteBuf 没有获取消息的所有字节。 我
我是 Netty 新手,并试图了解它是如何工作的。 我想在本地主机上创建一个简单的 SMTP 服务器用于测试目的,但我在理解编码器的工作原理时遇到了一个小问题。 首先这是我想要实现的目标。 客户端正在
这是我的服务器端代码。此代码在 netty 的帮助下读取 udp 流量。但是,有时我会出错....我无法修复它....这很悲哀...... @Override protected void
我正在尝试将 2 个 ByteBuf 合并为一个 ByteBuf,我该怎么做? import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpoo
如何从 netty ByteBuf 中获取字符串?截至目前,我能够逐个字符地获取它。有没有办法直接获取字符串对象? // message is of type ByteBuf for (int i =
我想将传入的 Netty 的 ButeBuf 消息转换为我的类的 MyBuffer 实例。为此,我使用这个 MessageToMessageDecoder: class ByteArrayDecode
您好,我们已经使用 netty 4.0 一段时间了,并且正在转向 4.1。由于遗留原因,我们正在以小字节序接收消息,并且在可预见的将来无法转向大字节序。 我们过去所做的是使用“ByteBuf.orde
在我的应用程序中,我需要在套接字上接收一个字节数组,将其解析为 HttpRequest 以执行一些检查,如果检查通过,则返回字节数组并执行更多操作工作。 该应用程序基于 NETTY(这是一个要求)。
我正在尝试使用 ByteBuf 通过 netty 发送字符串。首先,我将字符串转换为字节数组,如下所示: byteBuf.writeInt(this.serverName.length()); byt
我正在使用 EmbeddedChannel测试我的 handlers和 codecs以下列格式处理消息: +------------+------------------+-------------
我创建了一个 netty.io BootStrap,它从旧服务器接收流数据。服务器使用 ISO-8859-1 字符集发送数据。还有一个使用不同分隔符字节的内部“协议(protocol)”: priva
我正在尝试了解基于https://github.com/traccar/traccar解码aTrack协议(protocol)实现,他们使用Netty作为他们的平台实现,但我不明白ByteBuf对象的
我使用的是 netty 4.10beta6。 在 channel A 中,我通过覆盖 channelRead()(默认情况下使用池化 buf 分配器)读取了一个 ByteBuf,通过传递它来消耗和释放
有没有办法告诉 Netty 4 它创建的所有 ByteBuf 实例都应该具有 LITTLE_ENDIAN 字节序? 调用order(ByteOrder)在每个处理程序中都很烦人。 看起来 Netty
我是一名优秀的程序员,十分优秀!