Package java.net

Examples of java.net.SocketAddress


            SyslogSourceConfigurationConstants.DEFAULT_KEEP_FIELDS));
  }

  @VisibleForTesting
  public int getSourcePort() {
    SocketAddress localAddress = nettyChannel.getLocalAddress();
    if (localAddress instanceof InetSocketAddress) {
      InetSocketAddress addr = (InetSocketAddress) localAddress;
      return addr.getPort();
    }
    return 0;
View Full Code Here


    // one faker on port 10001
    int port1 = 10001;
    NioSession session1 = mock(NioSession.class);
    session1.setAttributeMap(dsFactory.getAttributeMap(session1));
    SocketAddress sockAddr1 = new InetSocketAddress(localAddr, port1);
    when(session1.getLocalAddress()).thenReturn(sockAddr1);

    // another faker on port 10002
    int port2 = 10002;
    NioSession session2 = mock(NioSession.class);
    session2.setAttributeMap(dsFactory.getAttributeMap(session2));
    SocketAddress sockAddr2 = new InetSocketAddress(localAddr, port2);
    when(session2.getLocalAddress()).thenReturn(sockAddr2);

    // set up expected charsets per port
    ConcurrentMap<Integer, ThreadSafeDecoder> portCharsets =
        new ConcurrentHashMap<Integer, ThreadSafeDecoder>();
View Full Code Here

            SyslogSourceConfigurationConstants.DEFAULT_KEEP_FIELDS));
  }

  @VisibleForTesting
  public int getSourcePort() {
    SocketAddress localAddress = nettyChannel.getLocalAddress();
    if (localAddress instanceof InetSocketAddress) {
      InetSocketAddress addr = (InetSocketAddress) localAddress;
      return addr.getPort();
    }
    return 0;
View Full Code Here

        if (log.isDebugEnabled()) {
            log.debug("Trying to connect to WKA member " + wkaMember + "...");
        }
        try {
            InetAddress addr = InetAddress.getByName(wkaMember.getHostName());
            SocketAddress sockAddr = new InetSocketAddress(addr, wkaMember.getPort());
            new Socket().connect(sockAddr, 10000);
            return true;
        } catch (IOException e) {
            if (log.isDebugEnabled()) {
                log.debug("", e);
View Full Code Here

                    int httpPort = member.getHttpPort();
                    if (log.isDebugEnabled()) {
                        log.debug("HTTP Port=" + httpPort);
                    }
                    if (httpPort != -1) {
                        SocketAddress httpSockaddr = new InetSocketAddress(addr, httpPort);
                        new Socket().connect(httpSockaddr, 10000);
                    }
                    int httpsPort = member.getHttpsPort();
                    if (log.isDebugEnabled()) {
                        log.debug("HTTPS Port=" + httpsPort);
                    }
                    if (httpsPort != -1) {
                        SocketAddress httpsSockaddr = new InetSocketAddress(addr, httpsPort);
                        new Socket().connect(httpsSockaddr, 10000);
                    }
                    return true;
                } catch (IOException e) {
                    if (log.isDebugEnabled()) {
View Full Code Here

public class FutureSocketChannelTest {
    @Test
    public void testEchoServer() throws Exception {
        final AtomicReference<String> result = new AtomicReference<>();
        final CountDownLatch latch = new CountDownLatch(1);
        SocketAddress serverSocket = new InetSocketAddress(0);
        final FutureServerSocketChannel fssc = new FutureServerSocketChannel().bind(serverSocket);
        Consumer<FutureSocketChannel> accepted = new Consumer<FutureSocketChannel>() {
            public void accept(FutureSocketChannel fsc) {
                fssc.accept().thenAccept(this);
                ByteBuffer bb = ByteBuffer.allocate(1024);
                fsc.read(bb).thenAccept(length -> {
                    bb.flip();
                    fsc.write(bb);
                    fsc.close();
                });
            }
        };
        fssc.accept().thenAccept(accepted);
        FutureSocketChannel fsc = new FutureSocketChannel();
        SocketAddress clientSocket = new InetSocketAddress("localhost", fssc.getLocalAddress().getPort());
        fsc.connect(clientSocket).thenAccept(v -> {
            fsc.write(ByteBuffer.wrap("hello".getBytes())).thenAccept(sent -> {
                ByteBuffer readBuffer = ByteBuffer.allocate(sent);
                fsc.read(readBuffer).thenAccept(recv -> {
                    readBuffer.flip();
View Full Code Here

        int timeout = params.getConnectionTimeout();

        Socket socket = new Socket(proxy);
        socket.setSoTimeout(timeout);

        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
        return socket;
    }
View Full Code Here

        if (timeout == 0) {
            return socketfactory.createSocket(host, port, localAddress, localPort);
        }
        else {
            Socket socket = socketfactory.createSocket();
            SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
            SocketAddress remoteaddr = new InetSocketAddress(host, port);
            socket.bind(localaddr);
            socket.connect(remoteaddr, timeout);
            return socket;
        }
    }
View Full Code Here

    if (temp.length == 2)
      port = Integer.valueOf(temp[1]).intValue();
    else
      port = 80;

    SocketAddress sockaddr = new InetSocketAddress(addr, port);
    Socket test = new Socket();
    int timeoutMs = 1000; // 1 second
    test.connect(sockaddr, timeoutMs);
    test.close();
    bool = true;
View Full Code Here

      {
         return null;
      }

      // HORNETQ-907 - strip off IPv6 scope-id (if necessary)
      SocketAddress remoteDestination = new InetSocketAddress(host, port);
      InetAddress inetAddress = ((InetSocketAddress) remoteDestination).getAddress();
      if (inetAddress instanceof Inet6Address)
      {
         Inet6Address inet6Address = (Inet6Address) inetAddress;
         if (inet6Address.getScopeId() != 0)
         {
            try
            {
               remoteDestination = new InetSocketAddress(InetAddress.getByAddress(inet6Address.getAddress()), ((InetSocketAddress) remoteDestination).getPort());
            }
            catch (UnknownHostException e)
            {
               throw new IllegalArgumentException(e.getMessage());
            }
         }
      }

      HornetQClientLogger.LOGGER.debug("Remote destination: " + remoteDestination);

      ChannelFuture future;
      //port 0 does not work so only use local address if set
      if (localPort != 0)
      {
         SocketAddress localDestination;
         if (localAddress != null)
         {
            localDestination = new InetSocketAddress(localAddress, localPort);
         }
         else
View Full Code Here

TOP

Related Classes of java.net.SocketAddress

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.