MulticastSocket and Runnable

67 Views Asked by At
 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?

1

There are 1 best solutions below

0
On

Your other code must be importing java.net.MulticastSocket, which doesn't implement Runnable.

Don't reuse class names from the JDK. And there is nothing 'multicast' about your class.