Code example for MulticastSocket

Methods: close, joinGroup, send, setTimeToLive

0
                if (config.host != null) {
                    InetAddress addr =  InetAddress.getByName(config.host);
                    InetSocketAddress addrs = new InetSocketAddress(addr, config.getMultiport());
                    s = new MulticastSocket(addrs);
                } else 
                    s = new MulticastSocket(config.getMultiport());
           
                s.setTimeToLive(config.getTtl());
                s.joinGroup(group);
            } catch (Exception ex) {
                log.error("Unable to use multicast: " + ex);
                s = null;
                return -1; 
            }  
        } 
 
        byte[] buf;
        buf = mess.getBytes(US_ASCII);
        DatagramPacket data = new DatagramPacket(buf, buf.length, group, config.getMultiport());
        try { 
            s.send(data);
        } catch (Exception ex) {
            log.error("Unable to send colllected load information: " + ex);
            s.close();
            s = null;
            return -1; 
        } 
        return 0; 
    }