Multicast problem, please help with ip "230.0.0.1"
843790Aug 27 2006 — edited Sep 12 2006hi all, i need your help concerning the ip 230.0.0.1, when i wanna joinGroup it with my client, an exception occured, so what is the problem?
ex:
MulticastSocket msocket = new MulticastSocket (5555);
InetAddress group = InetAddress.getByName ("230.0.0.1");
msocket.joinGroup (group); // here is an runtime exception thrown
show the code down:
************************* the code ***********************************
//In the name of ALLAH most gracious most merciful:
this exception on both win & linux
----------------------------------------------------------------------------------------------------
// Constants : contain the server's port no.
package messenger;
public interface Constants {
static final int SRV_PORT = 6666;
}
----------------------------------------------------------------------------------------------------
// The server in Server.java
package messenger;
import java.io.*;
import java.net.*;
public class Server implements Constants{
private static DatagramSocket dsocket;
private static DatagramPacket dpacket;
public static void displayStarting() throws InterruptedException{
System.out.print("Starting server .");
for ( int i = 0; i < 5; i++){
System.out.print(".");
Thread.sleep(200);
}
}
public static void main(String[] args) {
boolean opening = true;
try{
displayStarting();
// listening on the server dedecated port :
dsocket = new DatagramSocket(SRV_PORT);
while ( opening ){
dpacket = new DatagramPacket(new byte[5000], 5000);
// waiting a packet to come:
dsocket.receive(dpacket);
// extracting client info:
int clientPort = dpacket.getPort();
//InetAddress address = dpacket.getAddress(); //I will never need cause i send info to a shared IP add
// preparing the packet to send:
InetAddress sharedAdd = InetAddress.getByName("230.0.0.1");
dpacket = new DatagramPacket(dpacket.getData(), dpacket.getData().length, sharedAdd, clientPort);
dsocket.send(dpacket);
}
}catch(SocketException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}catch (InterruptedException e){
e.printStackTrace();
}finally{
dsocket.close();
}
}
}
----------------------------------------------------------------------------------------------------
// the client, the class that contains the problem
import java.net.*;
import java.io.*;
import messenger.Constants; // to obtain the server port no. : SRV_PORT
public class Client implements Constants{
private static MulticastSocket msocket ;
private static InetAddress group;
private static DatagramPacket dpacket ;
private static BufferedReader stdIn = new BufferedReader( new InputStreamReader( System.in));
public static void main(String[] args) {
if ( args.length != 1){
System.out.println("Usage : java -jar Messenger-Client <hostname>"+
"\nwhere <hostname> is the name of the machine that hosted the server program");
return;
}
try{
int client_port = 5555;
msocket = new MulticastSocket(client_port);
group = InetAddress.getByName("230.0.0.1");
msocket.joinGroup(group); // ===>> here is the problem, an exception thrown, the details is at the bottom.
String line ;
while ( ( line = stdIn.readLine()) != null ){
// preparing packet to send:
InetAddress hostAdd = InetAddress.getByName(args[0]);
dpacket = new DatagramPacket(line.getBytes(), line.getBytes().length, hostAdd, SRV_PORT);
msocket.send(dpacket);
// waiting server respone:
msocket.receive(dpacket);
System.out.println(new String(dpacket.getData()));
}
}catch (NumberFormatException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}finally{
try{
stdIn.close();
msocket.leaveGroup(group);
msocket.close();
}catch (IOException e){
e.printStackTrace();
}
}
}
}
---------------------------------------------------------------------------------------------------------------------------------------------
// the exception thrown by the client :
java.net.SocketException: No such device
at java.net.PlainDatagramSocketImpl.join(Native Method)
at java.net.PlainDatagramSocketImpl.join(PlainDatagramSocketImpl.java:172)
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:276)
at Client.main(Client.java:27)