sending frames using sockets
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
- 开发者_如何学JAVAReserved: 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 :/
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/
I really don't know what are this frames , should I assume
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.
精彩评论