Multicasting problem
Ok i have a multicasting client that sends a request to a multicast address 224.0.1.1. Can anyone please tell me why whenever i run this, either no connection at all happens, or the packet sent back to the client is just a copy of the request message the client sends:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.text.DecimalFormat;
import java.net.MulticastSocket;
public class SntpMulti
{
public static void main(String[] args) throws IOException
{
String serverName="224.0.1.1";
final int PORT = 123;
InetAddress local = InetAddress.getLocalHost();
InetAddress address = InetAddress.getByName(serverName);
MulticastSocket ms = new MulticastSocket(PORT);
//ms.setInterface(local);
ms.setTimeToLive(255);
byte[] buf = new NtpMessage().toByteArray();
DatagramPacket packet =
new DatagramPacket(buf, buf.length, address, PORT);
ms.send(packet);
System.out.println(""+ packet.getData());
// Get response
System.out.println("NTP request sent, waiting for response...\n");
ms.joinGroup(address);
ms.receive(packet);
System.out.println(""+ packet.getData());
System.out.println(""+ packet.getSocketAddress());
System.out.println("" + packet.getLength());
// Immediately record the incoming timestamp
double destinationTimestamp =
(System.currentTimeMillis()/1000.0) + 2208988800.0;
// Process response
NtpMessage msg = new NtpMessage(packet.getData());
double roundTripDelay = (destinationTimestamp-msg.originateTimestamp) -
(msg.transmitTimestamp-msg.receiveTimestamp);
double localClockOffset =
((msg.receiveTimestamp - msg.originateTimestamp) +
(msg.transmitTimestamp - destinationTimestamp)) / 2;
ms.leaveGroup(address);
ms.close();
}
}
This is really starting tp get on my nerves, any help would be appreciated, thanks. oh and just to be clear there is nothing wrong with the formatting which comes from another class but i know it is an problem with the multicast part, (unicast works fine ) =(

