Example usage for java.net Socket getInetAddress

List of usage examples for java.net Socket getInetAddress

Introduction

In this page you can find the example usage for java.net Socket getInetAddress.

Prototype

public InetAddress getInetAddress() 

Source Link

Document

Returns the address to which the socket is connected.

Usage

From source file:flens.input.SocketInput.java

@Override
public Pair<String, DataInputStream> getStream(Socket newSocket) throws IOException {
    String hostname = newSocket.getInetAddress().getHostName();
    return Pair.of(hostname, new DataInputStream(newSocket.getInputStream()));
}

From source file:flens.input.GraphiteInput.java

@Override
public Pair<String, BufferedReader> getStream(Socket newSocket) throws IOException {
    String hostname = newSocket.getInetAddress().getHostName();
    return Pair.of(hostname, new BufferedReader(new InputStreamReader(newSocket.getInputStream())));
}

From source file:org.apache.hadoop.thriftfs.ThriftServerContext.java

/**
 * Tries to get the client name for a given Thrift transport.
 * //w w  w  .ja  va  2 s.c  o  m
 * @param t the Thrift transport
 * @return The client name, if 'transport' was a socket, or
 *         "unknown-client:<random number>" otherwise.
 */
private String assignClientName() {
    Socket sock = getTransportSocket();
    if (sock != null) {
        return sock.getInetAddress().getHostAddress() + ":" + sock.getPort();
    }
    return "unknown-client:" + random.nextLong();
}

From source file:com.cooksys.httpserver.RequestListenerThread.java

@Override
public void run() {
    System.out.println("Listening on port " + this.serversocket);

    while (!Thread.interrupted()) {
        try {//from   w ww.  j a v  a2  s.c o  m
            // Listen for connections
            Socket socket = this.serversocket.accept();
            System.out.println("Incoming connection from " + socket.getInetAddress());

            //setup the http connection
            HttpServerConnection conn = this.connFactory.createConnection(socket);

            // Start worker thread
            Thread t = new WorkerThread(this.httpService, conn);
            t.setDaemon(true);
            t.start();
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            System.err.println("Connection interrupted. " + e.getMessage());
            break;
        }
    }

    //clean up socket connection before exiting thread

    System.out.println("Server thread exiting");

}

From source file:org.zaproxy.zap.extension.websocket.WebSocketProxy.java

/**
 * Factory method to create appropriate version.
 *
 * @param version Protocol version./*www  . j  a  va  2s.  com*/
 * @param localSocket Channel from browser to ZAP.
 * @param remoteSocket Channel from ZAP to server.
 * @param subprotocol Provide null if there is no subprotocol specified.
 * @param extensions Map of negotiated extensions, null or empty list.
 * @throws WebSocketException
 * @return Version specific proxy object.
 * @see #create(String, Socket, Socket, String, int, String, Map)
 */
public static WebSocketProxy create(String version, Socket localSocket, Socket remoteSocket, String subprotocol,
        Map<String, String> extensions) throws WebSocketException {
    return create(version, localSocket, remoteSocket, remoteSocket.getInetAddress().getHostName(),
            remoteSocket.getPort(), subprotocol, extensions);
}

From source file:de.xwic.appkit.core.cluster.impl.InboundConnectionHandler.java

@Override
public void run() {

    ServerSocket srvSocket;//from   ww  w .j  a va2 s.c  o m
    try {
        srvSocket = new ServerSocket(port);

    } catch (IOException e) {
        log.error("Can not open server socket", e);
        return; // exit
    }

    int conHandlerCount = 0;
    int errCount = 0;
    long lastErr = 0;
    while (true) {
        try {
            Socket socket = srvSocket.accept();

            log.debug("Accepted connection from " + socket.getInetAddress().getHostAddress());

            ClientHandler ch = new ClientHandler(cluster, socket);

            Thread t = new Thread(ch,
                    "ConnectionHandler-" + socket.getInetAddress().getHostAddress() + "-" + conHandlerCount++);
            t.setDaemon(true); // launch as a Deamon
            t.start();

        } catch (IOException e) {
            log.error("Error accepting incoming connection...", e);
            if ((System.currentTimeMillis() - lastErr) < 3000) { // the last error was just 3 seconds ago
                errCount++;
                if (errCount > 100) {
                    log.error("More than 100 errors occured within the last 3 seconds. Giving up.");
                    break; // break the loop
                }
            } else {
                errCount = 0;
            }
            lastErr = System.currentTimeMillis();
        }
    }

}

From source file:com.sittinglittleduck.DirBuster.EasySSLProtocolSocketFactoryUnitTest.java

@Test
public void shouldCreateSocketForGivenHostAndPort() throws Exception {
    // Given/*ww  w  .j  a  v a2  s. co  m*/
    String host = "localhost";
    int port = 18080;
    // When
    Socket sslSocket = socketFactory.createSocket(host, port);
    // Then
    assertThat(sslSocket.getInetAddress().getHostName(), is(equalTo(host)));
    assertThat(sslSocket.getPort(), is(equalTo(port)));
}

From source file:com.l2jfree.network.legacy.NetworkThread.java

protected final void initConnection(Socket con) throws IOException {
    _connection = con;/*from  ww  w  .  j av a  2  s  . c  om*/
    _connectionIp = con.getInetAddress().getHostAddress();

    _in = new BufferedInputStream(con.getInputStream());
    _out = new BufferedOutputStream(con.getOutputStream());

    _blowfish = new NewCipher("_;v.]05-31!|+-%xT!^[$\00");
}

From source file:com.l2jfree.network.NetworkThread.java

protected final void initConnection(Socket con) throws IOException {
    _connection = con;//from   w w  w .  j a v a  2  s . co  m
    _connectionIp = con.getInetAddress().getHostAddress();

    _in = new BufferedInputStream(con.getInputStream());
    _out = new BufferedOutputStream(con.getOutputStream());

    _blowfish = new NewCrypt("_;v.]05-31!|+-%xT!^[$\00");
}

From source file:org.openstatic.smtp.PlaceboSmtpServer.java

public void run() {
    ss = null;//from   w ww  .  j  a  v a2 s . c  o m
    try {
        ss = new ServerSocket(this.port);
        logln(this.myName, "Init on port " + String.valueOf(this.port));
    } catch (Exception n) {
        logln(this.myName, "Init Failed on port " + String.valueOf(this.port) + " / " + n.getMessage());
    }
    logln(this.myName, "Entering Server Loop");
    this.keep_running = true;
    while (this.keep_running) {
        try {
            logln(this.myName, "Waiting for next Socket....");
            Socket new_connection = ss.accept();
            logln(this.myName, "Connection Accepted " + new_connection.getInetAddress().getCanonicalHostName());
            SmtpRequestThread rt = new SmtpRequestThread(new_connection, this);
            rt.start();
        } catch (Exception x) {
            logln(this.myName, x.toString() + " / " + x.getMessage());
            x.printStackTrace(System.err);
        }
    }
}