udp 패킷에서 1 비트를 읽으려고합니다.udp 패킷에서 1 비트를 읽는 방법
UDP를 패킷이 (C 코드)과 같습니다
이struct typedef struct s_foo
{
__u32 foo;
__u8 bar:1,
bob:1;
} __attribute__((packed)) s_foo;
자바 난이 어떻게 읽을 수 있습니까?
이 그 값을 테스트합니다 :
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
public class BroadcastListener
{
public static void main(String[] args) throws IOException
{
if (args.length != 1) {
System.out.println("usage: <program> port");
System.exit(1);
}
int port = Integer.parseInt(args[0]);
DatagramSocket dgram = new DatagramSocket(port);
byte[] buffer = new byte[2048];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
while (true) {
dgram.receive(packet);
String msg = new String(buffer, 0, packet.getLength());
System.out.println(packet.getAddress().getHostName() + ": "
+ msg);
packet.setLength(buffer.length);
}
}
}
이 경우 대답으로 표시하십시오! –