使用套接字发送帧
我被要求制作一个使用套接字发送帧的JAVA应用程序,我的问题很简单,这个“帧”有什么特别的吗?我的意思是,我知道如何通过网络传输字节,我有关于套接字的知识,但我真的不知道这是什么帧,我是否应该假设通过说“帧”它们只是指特定的字节结构发送?
他们指定“帧”必须具有以下结构:
- 标头:E
- CRC:8AFE
- 日期:110825080000
- 最终硬币输入:2176
- 最终硬币输出:12345
- 保留:0
因此将其传递到十六进制是
- 45
- 8A FE
- 31 31 30 38 32 35 30 38 30 30 30 30
- 30 30 30 30 30 30 32 31 37 36
- 30 30 30 30 30 31 32 33 34 35
- 30 30 30 30 30 30 30 30 30 30
所以如果我正确,要发送的帧(我稍后将转换为字节)是:
45 8A FE 31 31 30 38 32 35 30 38 30 30 30 30 30 30 30 30 30 30 32 31 37 36 30 30 30 30 3031 32 33 34 35 30 30 30 30 30 30 30 30 30 30
我的问题是我的说法是否正确,还是我遗漏了什么?也许我完全错了? :s 预先感谢
PD:抱歉,如果这是一个愚蠢的问题:/
I've been asked to make a JAVA application for sending frames using sockets, my question is simple, is there anything special with this "frames"? i mean, i know how to transport bytes through net, I have knowledge about sockets, but I really don't know what are this frames , should i assume that by saying "frames" they are just referring to a specific structure of bytes to send?
they specify that the "frames" must have this structure:
- Header: E
- CRC: 8AFE
- Date: 110825080000
- Final Coin In: 2176
- Final Coin Out: 12345
- Reserved: 0
so passing this to hex is
- 45
- 8A FE
- 31 31 30 38 32 35 30 38 30 30 30 30
- 30 30 30 30 30 30 32 31 37 36
- 30 30 30 30 30 31 32 33 34 35
- 30 30 30 30 30 30 30 30 30 30
so if im correct, the frame (that i will convert to bytes later) to send is:
45 8A FE 31 31 30 38 32 35 30 38 30 30 30 30 30 30 30 30 30 30 32 31 37 36 30 30 30 30 3031 32 33 34 35 30 30 30 30 30 30 30 30 30 30
My question is am I correct about this, or am I missing something? maybe i'm completely wrong? :s
Thanks in advance
PD: sorry if this is a dumb question :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 套接字 API 工作在第 7 层。您可以发送 UDP 数据包或 TCP/IP 流,但无法使用标准 Java.net 包发送或接收以太网帧。
换句话说,您可以发送和接收有效负载,但不能读取或写入标头(例如 TCP 数据包或以太网帧标头)。
至少在没有编写自己的 JNI 代码或使用“原始套接字”的第 3 方库的情况下是这样。例如:https://www.savarese.com/software/rocksaw/
The Java sockets API works at Layer 7. You can send UDP packets or TCP/IP streams, but you cannot send or receive Ethernet frames with the standard Java.net package.
In other words, you can send and receive PAYLOADS, but you cannot read or write HEADERS (e.g. TCP-packet or Ethernet-frame headers).
At least not without writing your own JNI code, or using a 3rd party library for "raw sockets". For example: https://www.savarese.com/software/rocksaw/
不。您应该询问谁给了您这个要求。没有人想要猜谜游戏。
编辑:但是,我将添加两个观察结果。首先,在你的整个职业生涯中,任何人曾经要求你直接写出以太网帧的机会微乎其微。其次,这不是以太网帧格式,甚至谷歌也会告诉你。
No. You should ask whoever gave you the requirement. Nobody wants guessing games.
EDIT: however, I will add two observations. First, the chances of anyone ever asking you to write out Ethernet frames directly in your entire career are vanishingly small. Second, that is not an Ethernet frame format, as even Google would have told you.