Im trying to Send out a DatagramPacket on a MulticastSocket. This bit is working but when i try and get the info out of the header its not working.
while(true){
byte[] packet = new byte[1500];
DatagramPacket packetR = new DatagramPacket(packet, packet.length);
socketM.receive(packetR);
ByteBuffer data = ByteBuffer.wrap(packetR.getData());
byte[] senderAddress = new byte[100];
byte[] senderCommand =new byte[100];
data.get(senderAddress,0,4);
InetAddress senderIP = InetAddress.getByAddress(senderAddress);
data.position(4);
data.get(senderCommand,0,1);
String command = (char)senderCommand[0]+"";
System.out.print(senderIP+": "+ command+"\n");
}
This works but i just get all of it printed out
while(true){
byte[] packet = new byte[100];
DatagramPacket packetR = new DatagramPacket(packet, packet.length);
socketM.receive(packetR);
InetAddress ip = packetR.getAddress();
String meg = new String(packetR.getData());
System.out.print(ip+": "+ meg+"\n");
}
Can anyone see why this would not work thanks.