We use socket.send(packet) function in java to send a "packet" to a given port. My problem is that i have to send a packet to a shutdown system using UDP protocol. The problem with send() function is that first it verifies whether the host IP is multicast or not. Now my local area network is of broadcast type. So i am having problem is using this function. can anyone please give me a way ?
A:
Do you know how send udp packets in java?
First of all, broadcasting must be enabled in your network.
Then, all your servers must join to agreed multicast address.
InetAddress address = InetAddress.getByName( "230.0.0.1" );
MulticastSocket socket = new MulticastSocket( 12345 );
socket.joinGroup( address );
When you want to activate the system shutdown, send an agreed message (for example, "die") to the multicast address.
DatagramPacket packet = new DatagramPacket( buf, buf.length );
socket.receive( packet );
String received = new String( packet.getData(), 0, packet.getLength() );
The servers when accept that message should initiate a shutdown flow.
Seffi
2010-04-27 06:38:05
I am sorry to say but i think you have not got my problem clearly.see..i am making wake on lan.so i dont have to shut down the system but to wake up.now the problem is that...send() function works only in multicast.and my local area network is of broadcast type.so this send() function doesn't work.
2010-04-27 07:56:49
First of all, broadcast has nothing to do with it. *Multicasting* must be enabled in your network *routers*, *if you have any*. Secondly the OP isn't doing multicasting at all so the answer is irrelevant.
EJP
2010-04-28 04:45:14
i have downloaded the code for wake on lan....this is the code...String ipStr = "172.16.3.44";String macStr = "00-26-18-31-9B-E5";InetAddress address = InetAddress.getByName(ipStr);DatagramPacket packet = new DatagramPacket(bytes,bytes.length,address, PORT);DatagramSocket socket = new DatagramSocket();socket.send(packet);socket.close();here bytes is the magic packet.this code is doesnt switch on the distination machine..please help
2010-04-27 11:04:09
'The problem with send() function is that first it verifies whether the host IP is multicast or not.' *Why* is that a problem?
EJP
2010-04-28 04:48:14
But why is that a problem? It isn't, so the checkMulticast call described in the Javadoc don't take place.
EJP
2010-04-29 01:03:42