Package java.net

Examples of java.net.MulticastSocket.joinGroup()


                try {
                    //fake a discovery server to send back some canned messages.
                    InetAddress address = InetAddress.getByName("239.255.255.250");
                    MulticastSocket s = new MulticastSocket(Integer.parseInt(PORT));
                    s.setBroadcast(true);
                    s.joinGroup(address);
                    s.setReceiveBufferSize(64 * 1024);
                    s.setSoTimeout(5000);
                    byte[] bytes = new byte[64 * 1024];
                    DatagramPacket p = new DatagramPacket(bytes, bytes.length, address, Integer.parseInt(PORT));
                    s.receive(p);
View Full Code Here


                }
            }
            else {
                group_addr=InetAddress.getByName("224.0.0.36");
                sock=new MulticastSocket(7777);
                sock.joinGroup(group_addr);
            }

            if(debug) {
                System.out.println("Press key to start");
                System.in.read();
View Full Code Here

            return existingKey;
        }

        boolean success = false;
        try {
            msocket.joinGroup(mcastaddr, interf);
            success = true;
            return newKey;
        } finally {
            if (!success) {
                mcastKeys.remove(newKey);
View Full Code Here

            InetAddress someInet = InetAddress.getByName(DNSConstants.MDNS_GROUP);
            firstSocket = new MulticastSocket(MPORT);
            secondSocket = new MulticastSocket(MPORT);

            firstSocket.joinGroup(someInet);
            secondSocket.joinGroup(someInet);
            //
            DatagramPacket out = new DatagramPacket(firstMessage.getBytes("UTF-8"), firstMessage.length(), someInet, MPORT);
            DatagramPacket inFirst = new DatagramPacket(firstMessage.getBytes("UTF-8"), firstMessage.length(), someInet, MPORT);
            DatagramPacket inSecond = new DatagramPacket(firstMessage.getBytes("UTF-8"), firstMessage.length(), someInet, MPORT);
            Receive receiveSecond = new Receive(secondSocket, inSecond);
View Full Code Here

                String multicastGroup = System.getProperty("hazelcast.multicast.group");
                if (multicastGroup == null) {
                    multicastGroup = multicastConfig.getMulticastGroup();
                }
                multicastConfig.setMulticastGroup(multicastGroup);
                multicastSocket.joinGroup(InetAddress.getByName(multicastGroup));
                multicastSocket.setSoTimeout(1000);
                mcService = new MulticastService(this, multicastSocket);
                mcService.addMulticastListener(new NodeMulticastListener(this));
            }
        } catch (Exception e) {
View Full Code Here

         while (nis.hasMoreElements()) {
            retval = new MulticastSocket(port);
            NetworkInterface networkInterface = nis.nextElement();
            retval.setNetworkInterface(networkInterface);
            try {
               retval.joinGroup(mcast_addr);
               String msg = "Successfully bind to " + networkInterface;
               okTrace.append(msg).append('\n');
            } catch (IOException e) {
               e.printStackTrace();
               String msg = "Failed to bind to " + networkInterface + ".";
View Full Code Here

        String message = "Hello, world!";
        String longerMessage = message + " again.";
        String veryLongMessage = longerMessage + " Forever!";

        socket.joinGroup(group);
        socket.setSoTimeout(5000); // prevent eternal block in
                                   // socket.receive()
        // send & recieve packet
        byte[] sendData = message.getBytes();
        DatagramPacket sendDatagram = new DatagramPacket(sendData, 0,
View Full Code Here

        MulticastSocket socket = null;
        try {
            // open a multicast socket
            socket = new MulticastSocket(PORT);
            socket.setLoopbackMode(false); // false indecates doing loop back
            socket.joinGroup(InetAddress.getByName(ADDRESS));

            // send the datagram
            byte[] sendData = message.getBytes();
            DatagramPacket sendDatagram = new DatagramPacket(sendData, 0,
                    sendData.length, new InetSocketAddress(InetAddress
View Full Code Here

        if(local) {
            MulticastSocket send_sock=new MulticastSocket(PORT);
            send_sock.setTrafficClass(8);
            MulticastSocket recv_sock=new MulticastSocket(PORT);
            recv_sock.joinGroup(GROUP);
            recv_packet=new DatagramPacket(recv_buf, 0, recv_buf.length);
            for(int i=0; i < 10; i++) {
                start=System.currentTimeMillis();
                send_buf=Util.objectToByteBuffer(start);
                send_packet=new DatagramPacket(send_buf, 0, send_buf.length, GROUP, PORT);
View Full Code Here

                Util.sleep(1000);
            }
        }
        else {
            MulticastSocket recv_sock=new MulticastSocket(PORT);
            recv_sock.joinGroup(GROUP);
            recv_packet=new DatagramPacket(recv_buf, 0, recv_buf.length);
            System.out.println("receiver started");
            for(;;) {
                recv_sock.receive(recv_packet);
                start=((Long)Util.objectFromByteBuffer(recv_buf, recv_packet.getOffset(), recv_packet.getLength())).longValue();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.