Search in sources :

Example 46 with SocketAddress

use of java.net.SocketAddress in project databus by linkedin.

the class HttpRequestLoggingHandler method channelConnected.

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    SocketAddress remoteAddress = ctx.getChannel().getRemoteAddress();
    if (remoteAddress instanceof InetSocketAddress) {
        InetSocketAddress inetAddress = (InetSocketAddress) remoteAddress;
        _peerIp = inetAddress.getAddress().getHostAddress();
    } else {
        _peerIp = remoteAddress.toString();
    }
    _peerId = _peerIp;
    _connStartNano = System.nanoTime();
    _connBytes = 0;
    logConnectionStart();
    super.channelConnected(ctx, e);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 47 with SocketAddress

use of java.net.SocketAddress in project hazelcast by hazelcast.

the class TcpIpConnection method toString.

@Override
public String toString() {
    Socket socket = socketChannel.socket();
    SocketAddress localSocketAddress = socket != null ? socket.getLocalSocketAddress() : null;
    SocketAddress remoteSocketAddress = socket != null ? socket.getRemoteSocketAddress() : null;
    return "Connection[id=" + connectionId + ", " + localSocketAddress + "->" + remoteSocketAddress + ", endpoint=" + endPoint + ", alive=" + alive + ", type=" + type + "]";
}
Also used : SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Socket(java.net.Socket)

Example 48 with SocketAddress

use of java.net.SocketAddress in project hazelcast by hazelcast.

the class InitConnectionTask method bindSocket.

private void bindSocket(SocketChannel socketChannel) throws IOException {
    InetAddress inetAddress = getInetAddress();
    Socket socket = socketChannel.socket();
    if (connectionManager.useAnyOutboundPort()) {
        SocketAddress socketAddress = new InetSocketAddress(inetAddress, 0);
        socket.bind(socketAddress);
    } else {
        IOException ex = null;
        int retryCount = connectionManager.getOutboundPortCount() * 2;
        for (int i = 0; i < retryCount; i++) {
            int port = connectionManager.acquireOutboundPort();
            SocketAddress socketAddress = new InetSocketAddress(inetAddress, port);
            try {
                socket.bind(socketAddress);
                return;
            } catch (IOException e) {
                ex = e;
                logger.finest("Could not bind port[ " + port + "]: " + e.getMessage());
            }
        }
        throw ex;
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) Socket(java.net.Socket)

Example 49 with SocketAddress

use of java.net.SocketAddress in project gitblit by gitblit.

the class SshServerSessionFactory method createSession.

@Override
protected AbstractSession createSession(final IoSession io) throws Exception {
    log.info("creating ssh session from {}", io.getRemoteAddress());
    if (io instanceof MinaSession) {
        if (((MinaSession) io).getSession().getConfig() instanceof SocketSessionConfig) {
            ((SocketSessionConfig) ((MinaSession) io).getSession().getConfig()).setKeepAlive(true);
        }
    }
    final SshServerSession session = (SshServerSession) super.createSession(io);
    SocketAddress peer = io.getRemoteAddress();
    SshDaemonClient client = new SshDaemonClient(peer);
    session.setAttribute(SshDaemonClient.KEY, client);
    // TODO(davido): Log a session close without authentication as a
    // failure.
    session.addCloseSessionListener(new SshFutureListener<CloseFuture>() {

        @Override
        public void operationComplete(CloseFuture future) {
            log.info("closed ssh session from {}", io.getRemoteAddress());
        }
    });
    return session;
}
Also used : CloseFuture(org.apache.sshd.common.future.CloseFuture) MinaSession(org.apache.sshd.common.io.mina.MinaSession) SocketAddress(java.net.SocketAddress) SocketSessionConfig(org.apache.mina.transport.socket.SocketSessionConfig)

Example 50 with SocketAddress

use of java.net.SocketAddress in project zaproxy by zaproxy.

the class RelaxedX509TrustManager method createSocket.

/**
	 * Attempts to get a new socket connection to the given host within the
	 * given time limit.
	 * 
	 * @param host
	 *            the host name/IP
	 * @param port
	 *            the port on the host
	 * @param localAddress
	 *            the local host name/IP to bind the socket to
	 * @param localPort
	 *            the port on the local machine
	 * @param params
	 *            {@link HttpConnectionParams Http connection parameters}
	 * 
	 * @return Socket a new socket
	 * 
	 * @throws IOException
	 *             if an I/O error occurs while creating the socket
	 * @throws UnknownHostException
	 *             if the IP address of the host cannot be determined
	 * @throws 	ConnectTimeoutException        
	 */
@Override
public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        InetAddress hostAddress = getCachedMisconfiguredHost(host, port);
        if (hostAddress != null) {
            return clientSSLSockFactory.createSocket(hostAddress, port, localAddress, localPort);
        }
        try {
            SSLSocket sslSocket = (SSLSocket) clientSSLSockFactory.createSocket(host, port, localAddress, localPort);
            sslSocket.startHandshake();
            return sslSocket;
        } catch (SSLException e) {
            if (!e.getMessage().contains(CONTENTS_UNRECOGNIZED_NAME_EXCEPTION)) {
                throw e;
            }
            hostAddress = InetAddress.getByName(host);
            cacheMisconfiguredHost(host, port, hostAddress);
            return clientSSLSockFactory.createSocket(hostAddress, port, localAddress, localPort);
        }
    }
    Socket socket = clientSSLSockFactory.createSocket();
    SocketAddress localAddr = new InetSocketAddress(localAddress, localPort);
    socket.bind(localAddr);
    SocketAddress remoteAddr = new InetSocketAddress(host, port);
    socket.connect(remoteAddr, timeout);
    return socket;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SSLSocket(javax.net.ssl.SSLSocket) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) SSLException(javax.net.ssl.SSLException) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) ServerSocket(java.net.ServerSocket)

Aggregations

SocketAddress (java.net.SocketAddress)355 InetSocketAddress (java.net.InetSocketAddress)279 IOException (java.io.IOException)79 Test (org.junit.Test)73 Socket (java.net.Socket)48 InetAddress (java.net.InetAddress)35 Channel (org.jboss.netty.channel.Channel)33 SocketException (java.net.SocketException)27 UnknownHostException (java.net.UnknownHostException)25 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)23 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)23 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)20 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)19 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)19 Proxy (java.net.Proxy)18 HashMap (java.util.HashMap)17 DatagramPacket (java.net.DatagramPacket)16 ByteBuffer (java.nio.ByteBuffer)16 Logger (org.apache.log4j.Logger)16 Test (org.testng.annotations.Test)16