Package java.net

Examples of java.net.MulticastSocket


    public RTPSocketAdapter(InetAddress addr, int port, int ttl) throws IOException {

  try {

      if (addr.isMulticastAddress()) {
    dataSock = new MulticastSocket(port);
    ctrlSock = new MulticastSocket(port+1);
    ((MulticastSocket)dataSock).joinGroup(addr);
    ((MulticastSocket)dataSock).setTimeToLive(ttl);
    ((MulticastSocket)ctrlSock).joinGroup(addr);
    ((MulticastSocket)ctrlSock).setTimeToLive(ttl);
      } else {
View Full Code Here


         {            
            this.socket = createMulticastSocket(group, DetachedHANamingService.this.adGroupPort);
         }
         else
         {
            this.socket = new MulticastSocket(DetachedHANamingService.this.adGroupPort);
         }
        
         // If there is a valid bind address, set the socket interface to it        
         // Use the jndi bind address if there is no discovery address
         if (DetachedHANamingService.this.discoveryBindAddress == null)
View Full Code Here

     
      private MulticastSocket createMulticastSocket(InetAddress mcast_addr, int port) throws IOException
      {
        if(mcast_addr != null && !mcast_addr.isMulticastAddress()) {
            log.warn("mcast_addr (" + mcast_addr + ") is not a multicast address, will be ignored");
            return new MulticastSocket(port);
        }

        SocketAddress saddr=new InetSocketAddress(mcast_addr, port);
        MulticastSocket retval=null;

        try {
            retval=new MulticastSocket(saddr);
        }
        catch(IOException ex) {
            StringBuilder sb=new StringBuilder();
             String type=mcast_addr != null ? mcast_addr instanceof Inet4Address? "IPv4" : "IPv6" : "n/a";
             sb.append("could not bind to " + mcast_addr + " (" + type + " address)");
             sb.append("; make sure your mcast_addr is of the same type as the IP stack (IPv4 or IPv6).");
             sb.append("\nWill ignore mcast_addr, but this may lead to cross talking " +
                     "(see http://www.jboss.com/wiki/Edit.jsp?page=CrossTalking for details). ");
             sb.append("\nException was: " + ex);
             log.warn(sb);
        }
        if(retval == null)
        {
            retval=new MulticastSocket(port);
        }
        return retval;
    }
View Full Code Here

         ttl = Integer.parseInt(args[5]);
   }
  
   private void setUpSockets() throws IOException
   {
      sender = new MulticastSocket();
      sender.setInterface(senderAddress);
      sender.setTimeToLive(ttl);
     
      goodReceiver = new MulticastReceiver(goodMulticast);
      goodReceiver.startListener();
View Full Code Here

      private boolean stopping;
     
      MulticastReceiver(InetAddress mcastAddr) throws IOException
      {
         group = mcastAddr;
         socket = new MulticastSocket(mcastPort);
         socket.setInterface(receiverAddress);
         socket.joinGroup(mcastAddr);
      }
View Full Code Here

        } catch (URISyntaxException wontHappen) {
        }
    }

    protected DatagramSocket createSocket() throws IOException {
        MulticastSocket s = new MulticastSocket();
        s.setSendBufferSize(maxTraceDatagramSize);
        s.setBroadcast(broadcast);
        s.setLoopbackMode(true);
        s.setTimeToLive(timeToLive);
        return s;
    }
View Full Code Here

            "Listening for distributed nodes on IP multicast " + iManager.networkMulticastAddress + ":"
                + iManager.networkMulticastPort);

    dgram = new DatagramPacket(recvBuffer, recvBuffer.length);
    try {
      socket = new MulticastSocket(iManager.networkMulticastPort);
      socket.joinGroup(iManager.networkMulticastAddress);
    } catch (IOException e) {
      throw new OIOException(
          "Can't startup the Discovery Listener service to catch distributed server nodes, probably the IP MULTICAST is disabled in current network configuration: "
              + e.getMessage());
View Full Code Here

   
    protected void setupSocket() throws IOException {
        if (mcastBindAddress != null) {
            try {
                log.info("Attempting to bind the multicast socket to "+address+":"+port);
                socket = new MulticastSocket(new InetSocketAddress(address,port));
            } catch (BindException e) {
                /*
                 * On some plattforms (e.g. Linux) it is not possible to bind
                 * to the multicast address. In this case only bind to the
                 * port.
                 */
                log.info("Binding to multicast address, failed. Binding to port only.");
                socket = new MulticastSocket(port);
            }
        } else {
            socket = new MulticastSocket(port);
        }
        socket.setLoopbackMode(false);
        if (mcastBindAddress != null) {
      if(log.isInfoEnabled())
                log.info("Setting multihome multicast interface to:" +mcastBindAddress);
View Full Code Here

        new Thread(new Runnable() {
            public void run() {
                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);
                    SocketAddress sa = p.getSocketAddress();
                    String incoming = new String(p.getData(), 0, p.getLength(), "UTF-8");
                    int idx = incoming.indexOf("MessageID");
                    idx = incoming.indexOf('>', idx);
                    incoming = incoming.substring(idx + 1);
                    idx = incoming.indexOf("</");
                    incoming = incoming.substring(0, idx);
                    for (int x = 1; x < 4; x++) {
                        InputStream ins = WSDiscoveryClientTest.class.getResourceAsStream("msg" + x + ".xml");
                        String msg = IOUtils.readStringFromStream(ins);
                        msg = msg.replace("urn:uuid:883d0d53-92aa-4066-9b6f-9eadb1832366",
                                          incoming);
                        byte out[] = msg.getBytes("UTF-8");
                        DatagramPacket outp = new DatagramPacket(out, 0, out.length, sa);
                        s.send(outp);
                    }
                   
                    s.close();
                } catch (Throwable t) {
                    t.printStackTrace();
                }
            }
        }).start();
View Full Code Here

         // HORNETQ-874
         if (checkForLinux() || checkForSolaris() || checkForHp())
         {
            try
            {
               receivingSocket = new MulticastSocket(new InetSocketAddress(groupAddress, groupPort));
            }
            catch (IOException e)
            {
               HornetQClientLogger.LOGGER.ioDiscoveryError(groupAddress.getHostAddress(), groupAddress instanceof Inet4Address ? "IPv4" : "IPv6");

               receivingSocket = new MulticastSocket(groupPort);
            }
         }
         else
         {
            receivingSocket = new MulticastSocket(groupPort);
         }

         if (localAddress != null)
         {
            receivingSocket.setInterface(localAddress);
View Full Code Here

TOP

Related Classes of java.net.MulticastSocket

Copyright © 2018 www.massapicom. 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.