import java.net.*;
public class SendConfig
{
InetAddress SYSTEM_IP;
int SYSTEM_PORT = 5000;
InetAddress MULTICAST_IP;
int PORT = 6000;
int TTL = 1;
DatagramPacket sendPacket;
MulticastSocket socket;
public ststic void main(String[] args)
{
new SendConfig().sendUDP();
}
SendConfig()
{
try
{
SYSTEM_IP = InetAddress.getByName("192.168.1.6");
MULTICAST_IP = InetAddress.getByName("226.1.1.1");
SocketAddress socket_address = new InetSocketAddress(SYSTEM_IP,SYSTEM_PORT);
socket = new MulticastSocket(socket_address);
socket.connect(MULTICAST_IP,PORT);
NetworkInterface NI = NetworkInterface.getByName("eth0");
socket.setNetworkInterface(NI);
socket.setInterface(SYSTEM_IP);
socket.setTimeToLive(TTL);
sendUDP(datagram);
}
catch(Exception E)
{
System.out.println("In Constructor :: "+E);
}
}
void sendUDP()
{
byte[] config_datagram = {'h','e','l','l','o'};
Thread thr = new Thread()
{
public void run()
{
try
{
while(true)
{
sendPacket = new DatagramPacket(config_datagram ,config_datagram .length);
socket.send(sendPacket);
sleep(1000);
}
}
catch(Exception E)
{
System.out.println("in Sending :: "+E);
}
}
};
thr.start();
}
}