微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.net.StandardProtocolFamily的实例源码

项目:jdk8u-jdk    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,InetAddress srcAddress,int port,int ttl)
        throws IOException,JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setoption(StandardSocketoptions.so_REUSEADDR,true);
    channel.setoption(StandardSocketoptions.IP_MULTICAST_TTL,ttl);

    // with srcAddress equal to null,this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress,0));
        } catch (UnsupportedAddresstypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setoption(StandardSocketoptions.IP_MULTICAST_IF,interf);
    }
}
项目:Openjsharp    文件SocketoptionRegistry.java   
private static Map<RegistryKey,OptionKey> options() {                  
    Map<RegistryKey,OptionKey> map =                                   
        new HashMap<RegistryKey,OptionKey>();                          
    map.put(new RegistryKey(StandardSocketoptions.so_broADCAST,Net.UNSPEC),new OptionKey(1,6));
    map.put(new RegistryKey(StandardSocketoptions.so_KEEPALIVE,9));
    map.put(new RegistryKey(StandardSocketoptions.so_LINGER,13));
    map.put(new RegistryKey(StandardSocketoptions.so_SNDBUF,7));
    map.put(new RegistryKey(StandardSocketoptions.so_RCVBUF,8));
    map.put(new RegistryKey(StandardSocketoptions.so_REUSEADDR,2));
    map.put(new RegistryKey(StandardSocketoptions.TCP_NODELAY,new OptionKey(6,1));
    map.put(new RegistryKey(StandardSocketoptions.IP_TOS,StandardProtocolFamily.INET),new OptionKey(0,1));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_IF,32));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_TTL,33));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_LOOP,34));
    map.put(new RegistryKey(StandardSocketoptions.IP_TOS,StandardProtocolFamily.INET6),new OptionKey(41,67));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_IF,17));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_TTL,18));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_LOOP,19));
    map.put(new RegistryKey(ExtendedSocketoption.so_OOBINLINE,10));
    return map;                                                        
}
项目:Openjsharp    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,new OptionKey(SocketoptionLevel.socket,SocketoptionName.broadcast));
    map.put(new RegistryKey(StandardSocketoptions.so_KEEPALIVE,SocketoptionName.KeepAlive));
    map.put(new RegistryKey(StandardSocketoptions.so_LINGER,SocketoptionName.Linger));
    map.put(new RegistryKey(StandardSocketoptions.so_SNDBUF,SocketoptionName.SendBuffer));
    map.put(new RegistryKey(StandardSocketoptions.so_RCVBUF,SocketoptionName.ReceiveBuffer));
    map.put(new RegistryKey(StandardSocketoptions.so_REUSEADDR,SocketoptionName.ReuseAddress));
    map.put(new RegistryKey(StandardSocketoptions.TCP_NODELAY,new OptionKey(SocketoptionLevel.Tcp,SocketoptionName.NoDelay));
    map.put(new RegistryKey(StandardSocketoptions.IP_TOS,new OptionKey(SocketoptionLevel.IP,SocketoptionName.TypeOfService));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_IF,SocketoptionName.MulticastInterface));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_TTL,SocketoptionName.IpTimetoLive));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_LOOP,SocketoptionName.MulticastLoopback));
    map.put(new RegistryKey(StandardSocketoptions.IP_TOS,new OptionKey(SocketoptionLevel.IPv6,ikvm.internal.Winsock.IPV6_TCLASS));
    map.put(new RegistryKey(StandardSocketoptions.IP_MULTICAST_IF,SocketoptionName.MulticastLoopback));
    map.put(new RegistryKey(ExtendedSocketoption.so_OOBINLINE,SocketoptionName.OutOfBandInline));
    return map;                                                        
}
项目:bt    文件AddressUtils.java   
public static InetAddress getDefaultRoute(Class<? extends InetAddress> type) {
    InetAddress target = null;

    ProtocolFamily family = type == Inet6Address.class ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    try(DatagramChannel chan=DatagramChannel.open(family)) {
        if(type == Inet4Address.class)
            target = InetAddress.getByAddress(new byte[] {8,8,8});
        if(type == Inet6Address.class)
            target = InetAddress.getByName("2001:4860:4860::8888");

        chan.connect(new InetSocketAddress(target,63));

        InetSocketAddress soa = (InetSocketAddress) chan.getLocalAddress();
        InetAddress local = soa.getAddress();

        if(type.isinstance(local) && !local.isAnyLocalAddress())
            return local;
        return null;
    } catch (IOException e) {
        e.printstacktrace();
        return null;
    }
}
项目:bt    文件OpentrackerLiveSync.java   
@Override
public void start(Collection<DHT> dhts,ConfigReader config) {
    try {
        channel = DatagramChannel.open(StandardProtocolFamily.INET);
        channel.setoption(StandardSocketoptions.IP_MULTICAST_TTL,1);
        channel.setoption(StandardSocketoptions.so_REUSEADDR,true);
        // we only need to send,not to receive,so need to bind to a specific port
        channel.bind(new InetSocketAddress(0));
        channel.connect(new InetSocketAddress(InetAddress.getByAddress(new byte[] {(byte) 224,23,5}),9696));
    } catch (IOException e) {
        e.printstacktrace();
        return;
    }

    t.setDaemon(true);
    t.setName("opentracker-sync");
    t.start();

    // OT-sync only supports ipv4 atm
    dhts.stream().filter(d -> d.getType().PREFERRED_ADDRESS_TYPE == Inet4Address.class).forEach(d -> {
        d.addIncomingMessageListener(this::incomingPacket);
    });

}
项目:bt    文件LocalServicediscoveryInfo.java   
public LocalServicediscoveryInfo(
        Set<SocketChannelConnectionAcceptor> socketAcceptors,Collection<AnnounceGroup> announceGroups) {

    this.localPorts = unmodifiableSet(collectLocalPorts(socketAcceptors));

    Collection<NetworkInterface> networkInterfaces = new HashSet<>();
    boolean acceptIP4 = false;
    boolean acceptIP6 = false;
    for (SocketChannelConnectionAcceptor acceptor : socketAcceptors) {
        networkInterfaces.add(acceptor.getNetworkInterface());
        InetSocketAddress address = acceptor.getLocalAddress();
        ProtocolFamily protocolFamily = InternetProtocolUtils.getProtocolFamily(address.getAddress());
        if (protocolFamily == StandardProtocolFamily.INET) {
            acceptIP4 = true;
        } else {
            acceptIP6 = true;
        }
        if (acceptIP4 && acceptIP6) {
            break; // no need to look further
        }
    }

    this.compatibleGroups = unmodifiableCollection(collectCompatibleGroups(announceGroups,acceptIP4,acceptIP6));
    this.networkInterfaces = unmodifiableCollection(networkInterfaces);
}
项目:netcrusher-java    文件DatagramBulkClient.java   
public DatagramBulkClient(String name,InetSocketAddress bindAddress,InetSocketAddress connectAddress,long limit,CyclicBarrier readBarrier,CyclicBarrier sentBarrier) throws IOException
{
    this.channel = DatagramChannel.open(StandardProtocolFamily.INET);
    this.channel.configureBlocking(true);
    this.channel.bind(bindAddress);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Bulk client {}: BIND<{}> CONNECT<{}>",new Object[]{name,bindAddress,connectAddress});
    }

    this.consumer = new Consumer(channel,name,limit,connectAddress,readBarrier);
    this.producer = new Producer(channel,sentBarrier);
}
项目:jdk8u_jdk    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,interf);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,interf);
    }
}
项目:parity-extras    文件MarketData.java   
public static MarketData open(NetworkInterface multicastInterface,InetSocketAddress multicastGroup,InetSocketAddress requestAddress,long instrument) throws IOException {
    DatagramChannel channel = DatagramChannel.open(StandardProtocolFamily.INET);

    channel.setoption(StandardSocketoptions.so_REUSEADDR,true);
    channel.bind(new InetSocketAddress(multicastGroup.getPort()));
    channel.join(multicastGroup.getAddress(),multicastInterface);
    channel.configureBlocking(false);

    DatagramChannel requestChannel = DatagramChannel.open(StandardProtocolFamily.INET);

    requestChannel.configureBlocking(false);

    return new MarketData(channel,requestChannel,requestAddress,instrument);
}
项目:mldht    文件AddressUtils.java   
public static InetAddress getDefaultRoute(Class<? extends InetAddress> type) {
    InetAddress target = null;

    ProtocolFamily family = type == Inet6Address.class ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    try(DatagramChannel chan=DatagramChannel.open(family)) {
        if(type == Inet4Address.class)
            target = InetAddress.getByAddress(new byte[] {8,63));

        InetSocketAddress soa = (InetSocketAddress) chan.getLocalAddress();
        InetAddress local = soa.getAddress();

        if(type.isinstance(local) && !local.isAnyLocalAddress())
            return local;
        return null;
    } catch (IOException e) {
        e.printstacktrace();
        return null;
    }
}
项目:mldht    文件OpentrackerLiveSync.java   
@Override
public void start(Collection<DHT> dhts,9696));
    } catch (IOException e) {
        e.printstacktrace();
        return;
    }

    t.setDaemon(true);
    t.setName("opentracker-sync");
    t.start();

    // OT-sync only supports ipv4 atm
    dhts.stream().filter(d -> d.getType().PREFERRED_ADDRESS_TYPE == Inet4Address.class).forEach(d -> {
        d.addIncomingMessageListener(this::incomingPacket);
    });

}
项目:wot_gateways    文件BasicMulticastSocketHandler.java   
public BasicMulticastSocketHandler(ChannelManager channelManager,InetAddress multicastIP) throws IOException {
    logger.addAppender(new ConsoleAppender(new SimpleLayout()));
    // ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF:
    logger.setLevel(Level.WARN);

    NetworkInterface interf = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
    //NetworkInterface interf = NetworkInterface.getByName("eth0");

    this.channelManager = channelManager;
    mcastChannel = DatagramChannel.open(StandardProtocolFamily.INET);
    mcastChannel.setoption(StandardSocketoptions.so_REUSEADDR,true);
    mcastChannel.bind(new InetSocketAddress(port));     
    mcastChannel.setoption(StandardSocketoptions.IP_MULTICAST_IF,interf);
    mcastChannel.join(multicastIP,interf);
    mcastChannel.configureBlocking(false);

    this.localPort = mcastChannel.socket().getLocalPort();
    this.localAddr = multicastIP;

    workerThread = new WorkerThread();
    workerThread.start();
}
项目:openhab-ulux-binding    文件UluxBinding.java   
private void startListenerThread() {
    try {
        this.channel = DatagramChannel.open(StandardProtocolFamily.INET);
        this.channel.socket().bind(configuration.getBindSocketAddress());
    } catch (final IOException e) {
        throw new UluxException("Could not open UDP port for listening!",e);
    }

    this.thread = new Thread(this);
    this.thread.start();

    this.audioChannel = new AudioChannel(configuration,providers);
    this.audioChannel.start();

    this.commandHandler.activate(audioChannel.getChannel(),channel,executorService);
    this.stateUpdateHandler.activate(audioChannel.getChannel(),executorService);

}
项目:openhab-ulux-binding    文件AudioChannel.java   
public void start() {
    this.audioSource = new AudioReceiver(configuration,providers);
    this.audioSource.start();

    try {
        this.channel = DatagramChannel.open(StandardProtocolFamily.INET);
        this.channel.socket().bind(configuration.getAudioSocketAddress());
    } catch (final IOException e) {
        throw new UluxException("Could not open UDP port for listening!",e);
    }

    this.listenerThread = new Thread(this,"u::Lux audio listener");
    this.listenerThread.start();

    // Todo AudioReceiver?
}
项目:infobip-open-jdk-8    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,interf);
    }
}
项目:jdk8u-dev-jdk    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,interf);
    }
}
项目:OLD-OpenJDK8    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,interf);
    }
}
项目:openjdk-jdk7u-jdk    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,interf);
    }
}
项目:openjdk-icedtea7    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,interf);
    }
}
项目:URingpaxos    文件Acceptor.java   
/**
 * Public constructor
 * 
 * @param id proposer id
 * @param config path to config file
 * @throws IOException 
 */
public Acceptor(int id,String config) throws IOException{
    this.ID = id;
    if(Configuration.getConfiguration().isEmpty()){
        Configuration.read(config);
    }

    NetworkInterface i = NetworkInterface.getByName(Configuration.getInterface());
    channel = DatagramChannel.open(StandardProtocolFamily.INET)
         .setoption(StandardSocketoptions.so_REUSEADDR,true)
         .bind(Configuration.getGroup(paxosRole.Acceptor))
         .setoption(StandardSocketoptions.IP_MULTICAST_IF,i);
    channel.configureBlocking(false);
    channel.join(Configuration.getGroup(paxosRole.Acceptor).getAddress(),i);

    for(int n=0;n<threadCount;n++){
        executer.execute(new AcceptorListener(this));
    }
}
项目:URingpaxos    文件Learner.java   
/**
 * Public constructor
 * 
 * @param id proposer id
 * @param config path to config file
 * @throws IOException 
 */
public Learner(int id,String config) throws IOException{
    this.ID = id;
    if(Configuration.getConfiguration().isEmpty()){
        Configuration.read(config);
    }
    NetworkInterface i = NetworkInterface.getByName(Configuration.getInterface());
    this.channel = DatagramChannel.open(StandardProtocolFamily.INET)
         .setoption(StandardSocketoptions.so_REUSEADDR,true)
         .bind(Configuration.getGroup(paxosRole.Learner))
         .setoption(StandardSocketoptions.IP_MULTICAST_IF,i);
    this.channel.configureBlocking(false);
    this.channel.join(Configuration.getGroup(paxosRole.Learner).getAddress(),i);
    for(int n=0;n<threadCount;n++){
        executer.execute(new LearnerListener(this));
    }
    writer.execute(new LearnerWriter(this));
}
项目:MyDMAM    文件Netdiscover.java   
Group(InetSocketAddress group_socket) throws IOException {
    this.group_socket = group_socket;

    if (group_socket.getAddress() instanceof Inet4Address) {
        pf = StandardProtocolFamily.INET;
    } else {
        pf = StandardProtocolFamily.INET6;
    }

    InetAddress first_addrnetwork_interface = network_interface.getInterfaceAddresses().stream().map(inet -> {
        return inet.getAddress();
    }).filter(inet_addr -> {
        return pf == StandardProtocolFamily.INET & inet_addr instanceof Inet4Address | pf == StandardProtocolFamily.INET6 & inet_addr instanceof Inet6Address;
    }).findFirst().orElseThrow(() -> new IOException("Can't found IPv4/6 addr in a IPv6/4 link"));

    bind_to = new InetSocketAddress(group_socket.getPort());
    if (SystemUtils.IS_OS_WINDOWS) {
        bind_to = new InetSocketAddress(first_addrnetwork_interface,group_socket.getPort());
    }
}
项目:yass    文件PriceReceiver.java   
public static void main(final String... args) throws Exception {
    final SimpleTransportSetup setup = new SimpleTransportSetup(
        Config.MESSAGE_SERIALIZER,new Server(
            Config.INITIATOR.priceListener.service(new PriceListener() {
                @Override public void newPrices(final List<Price> prices) {
                    final Price price = prices.get(0);
                    System.out.println("received " + price.kind + ": " + price.value);
                }
            })
        )
    );
    final DatagramChannel channel = DatagramChannel.open(StandardProtocolFamily.INET)
        .setoption(StandardSocketoptions.so_REUSEADDR,true)
        .bind(new InetSocketAddress(PriceSender.PORT));
    final NetworkInterface networkInterface = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
    channel.join(InetAddress.getByName(PriceSender.GROUP_BID),networkInterface);
    channel.join(InetAddress.getByName(PriceSender.GROUP_ASK),networkInterface);
    while (true) {
        DatagramTransport.invoke(setup,128);
    }
}
项目:javapgm    文件SourcePathMessage.java   
public static SocketBuffer create (ProtocolFamily family,int flags) {
                int tpdu_length = Packet.SIZEOF_pgm_HEADER;
                if (StandardProtocolFamily.INET6 == family)
                        tpdu_length += SIZEOF_SPM6_HEADER;
                else
                        tpdu_length += SIZEOF_SPM_HEADER;
                if (Packet.pgm_OPT_FIN == flags)
                {
                        tpdu_length += Packet.SIZEOF_pgm_OPT_LENGTH;
/* End of session */
                        if (Packet.pgm_OPT_FIN == flags)
                                tpdu_length += Packet.SIZEOF_pgm_OPT_HEADER + Packet.SIZEOF_pgm_OPT_FIN;
                }
                SocketBuffer skb = new SocketBuffer (tpdu_length);
        skb.setHeaderOffset (0);
        skb.getHeader().setType (Packet.pgm_SPM);
        skb.reserve (Packet.SIZEOF_pgm_HEADER);
                return skb;
        }
项目:openjdk-jdk10    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);

        if (interf == null) {
            throw new JdpException("Unable to get network interface for " + srcAddress.toString());
        }

        if (!interf.isUp()) {
            throw new JdpException(interf.getName() + " is not up.");
        }

        if (!interf.supportsMulticast()) {
            throw new JdpException(interf.getName() + " does not support multicast.");
        }

        try {
            channel.bind(new InetSocketAddress(srcAddress,interf);
    }
}
项目:openjdk9    文件Jdpbroadcaster.java   
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public Jdpbroadcaster(InetAddress address,interf);
    }
}
项目:bt    文件AnnounceGroupChannel.java   
private synchronized DatagramChannel getChannel() throws IOException {
    if (channel == null || !channel.isopen()) {
        if (shutdown.get()) {
            throw new IllegalStateException("Channel has been shut down");
        }
        ProtocolFamily protocolFamily = InternetProtocolUtils.getProtocolFamily(group.getAddress().getAddress());
        DatagramChannel _channel = selector.provider().openDatagramChannel(protocolFamily);
        _channel.setoption(StandardSocketoptions.so_REUSEADDR,true);
        // bind to any-local before setting TTL
        int port = group.getAddress().getPort();
        if (protocolFamily == StandardProtocolFamily.INET) {
            _channel.bind(new InetSocketAddress(Inet4Address.getByName("0.0.0.0"),port));
        } else {
            _channel.bind(new InetSocketAddress(Inet6Address.getByName("[::]"),port));
        }
        int timetoLive = group.getTimetoLive();
        if (timetoLive != 1) {
            _channel.setoption(StandardSocketoptions.IP_MULTICAST_TTL,timetoLive);
        }

        for (NetworkInterface iface : networkInterfaces) {
            _channel.join(group.getAddress().getAddress(),iface);
        }

        _channel.configureBlocking(false);
        channel = _channel;
    }
    return channel;
}
项目:bt    文件InternetProtocolUtils.java   
/**
 * @return {@link StandardProtocolFamily#INET} for IPv4 address or {@link StandardProtocolFamily#INET6} for IPv6 address
 * @throws IllegalArgumentException if the address is neither IPv4 or IPv6
 * @since 1.6
 */
public static ProtocolFamily getProtocolFamily(InetAddress address) {
    if (address.getAddress().length == IP4_BYTES) {
        return StandardProtocolFamily.INET;
    } else if (address.getAddress().length == IP6_BYTES) {
        return StandardProtocolFamily.INET6;
    } else {
        throw new IllegalArgumentException("Can't determine protocol family for address: " + address);
    }
}
项目:netcrusher-java    文件CrusherDatagramSocat6Test.java   
@Before
public void setUp() throws Exception {
    reactor = new NioReactor();

    crusher = DatagramCrusherBuilder.builder()
        .withReactor(reactor)
        .withBindAddress(ADDR_LOOPBACK6,PORT_DIRECT)
        .withConnectAddress(ADDR_LOOPBACK6,PORT_PROXY)
        .withProtocolFamily(StandardProtocolFamily.INET6)
        .withCreationListener((addr) -> LOGGER.info("Client is created <{}>",addr))
        .withDeletionListener((addr,byteMeters,packetMeters) -> LOGGER.info("Client is deleted <{}>",addr))
        .buildAndopen();
}
项目:netcrusher-java    文件CrusherDatagramSocat4Test.java   
@Before
public void setUp() throws Exception {
    reactor = new NioReactor();

    crusher = DatagramCrusherBuilder.builder()
        .withReactor(reactor)
        .withBindAddress(ADDR_LOOPBACK4,PORT_DIRECT)
        .withConnectAddress(ADDR_LOOPBACK4,PORT_PROXY)
        .withProtocolFamily(StandardProtocolFamily.INET)
        .withCreationListener((addr) -> LOGGER.info("Client is created <{}>",addr))
        .buildAndopen();
}
项目:netcrusher-java    文件DatagramBulkReflector.java   
public DatagramBulkReflector(String name,CyclicBarrier readBarrier) throws IOException {
    this.channel = DatagramChannel.open(StandardProtocolFamily.INET);
    this.channel.configureBlocking(true);
    this.channel.bind(bindAddress);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Bulk reflector {}: BIND<{}>",bindAddress});
    }

    this.reflector = new Reflector(channel,readBarrier);
}
项目:angler    文件ExampleApplication.java   
private static DatagramChannel multicastListener(final InetAddress address,final int port) throws IOException
{
    final NetworkInterface networkInterface = getMulticastCapableNetworkInterface();
    final DatagramChannel channel = DatagramChannel.open(StandardProtocolFamily.INET);
    channel.bind(new InetSocketAddress(address,port));
    channel.setoption(StandardSocketoptions.so_REUSEADDR,true);
    channel.setoption(StandardSocketoptions.IP_MULTICAST_IF,networkInterface);
    channel.join(address,networkInterface);

    return channel;
}
项目:angler    文件ExampleApplication.java   
private static DatagramChannel createListeningChannelOnPort(final InetSocketAddress local) throws IOException
{
    return DatagramChannel.open(StandardProtocolFamily.INET).
            setoption(StandardSocketoptions.so_REUSEADDR,true).
            setoption(StandardSocketoptions.so_RCVBUF,4096).
            bind(local);
}
项目:netty4.0.27Learn    文件ProtocolFamilyConverter.java   
/**
 * Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7.
 */
public static ProtocolFamily convert(InternetProtocolFamily family) {
    switch (family) {
    case IPv4:
        return StandardProtocolFamily.INET;
    case IPv6:
        return StandardProtocolFamily.INET6;
    default:
        throw new IllegalArgumentException();
    }
}
项目:wot_gateways    文件BasicMulticastSocketHandler.java   
public BasicMulticastSocketHandler(ChannelManager channelManager)
        throws IOException {
    this.channelManager = channelManager;
    mcastChannel = DatagramChannel.open(StandardProtocolFamily.INET);
    mcastChannel.socket().bind(new InetSocketAddress(0)); // port can be 0,// then a free
                                                            // port is
                                                            // chosen
    this.localPort = mcastChannel.socket().getLocalPort();
    mcastChannel.configureBlocking(false);

    workerThread = new WorkerThread();
    workerThread.start();

}
项目:eborp    文件AutoDetectingServerConfig.java   
private DatagramChannel createReceiveChannel() throws IOException {
    final String nicName = properties.getProperty(PropertiesReader.NETWORK_INTERFACE);
    final NetworkInterface networkInterface = getNetworkInterface(nicName);

    final DatagramChannel channel = DatagramChannel.open(StandardProtocolFamily.INET);
    channel.setoption(StandardSocketoptions.so_REUSEADDR,true)
            .bind(new InetSocketAddress(ANNOUNCE_PORT))
            .setoption(StandardSocketoptions.IP_MULTICAST_IF,networkInterface);

    final InetAddress group = InetAddress.getByName(MULTICAST_GROUP);
    channel.join(group,networkInterface);

    return channel;
}
项目:eborp    文件UdpDataSink.java   
public UdpDataSink(ServerConfig serverConfig) {
    System.out.println("opening UDP channel for sending");
    try {
        channel = DatagramChannel.open(StandardProtocolFamily.INET);
        channel.connect(new InetSocketAddress(serverConfig.getInetAddress(),serverConfig.getPort()));
    } catch (IOException e) {
        throw new IllegalStateException("Unable to start UDP channel for sending",e);
    }
}
项目:nls-net-ssdp    文件SsdpChannel.java   
private DatagramChannel createChannel(NetworkInterface networkIf,InetSocketAddress address,SsdpSelector selector)
        throws IOException {
    DatagramChannel channel = DatagramChannel.open(StandardProtocolFamily.INET)
            .setoption(StandardSocketoptions.so_REUSEADDR,true)
            .bind(address)
            .setoption(StandardSocketoptions.IP_MULTICAST_IF,networkIf);
    channel.join(SSDP_MCAST_ADDRESS.getAddress(),networkIf);
    channel.configureBlocking(false);
    selector.register(this,channel);
    return channel;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。