public class MulticastSocket extends DatagramSocket implements Runnable {
public String ip = "192.168.254.6";
public static int port = 12346;
public MulticastSocket(int port) throws SocketException {
super(port);
// TODO Auto-generated constructor stub
}
@Override
public void run() {
while (true) {
try {
getMessage(port, ip);
}
catch (Exception e) {
}
}
}
I have this code, I want to instantiate the Thread of this object from another class, it gives cast exception (cast to Runnable). What is the problem?
Your other code must be importing
java.net.MulticastSocket, which doesn't implementRunnable.Don't reuse class names from the JDK. And there is nothing 'multicast' about your class.