Example usage for java.net Socket hashCode

List of usage examples for java.net Socket hashCode

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:Main.java

/**
 * Renders the details of a socket in the returned string
 * @param socket The socket to render//w  ww.  ja  va 2s .c om
 * @return the details of the socket as a string
 */
public static String render(Socket socket) {
    if (socket == null)
        return "NULL";
    StringBuilder b = new StringBuilder("\nSocket [");
    b.append("\n\tLocalPort:").append(socket.getLocalPort());
    b.append("\n\tLocalAddress:").append(socket.getLocalAddress());
    b.append("\n\tLocalSocketAddress:").append(socket.getLocalSocketAddress());
    b.append("\n\tRemotePort:").append(socket.getPort());
    b.append("\n\tRemoteAddress:").append(socket.getInetAddress());
    b.append("\n\tRemoteSocketAddress:").append(socket.getRemoteSocketAddress());
    b.append("\n\tChannel:").append(socket.getChannel());
    b.append("\n\tHashCode:").append(socket.hashCode());
    b.append("\n]");
    return b.toString();
}

From source file:com.googlecode.jcimd.DummyCimdServer.java

public void start() throws IOException {
    this.serverSocket = new ServerSocket(this.port);
    if (this.logger.isInfoEnabled()) {
        this.logger.info("Listening on port " + this.port);
    }//from   w w w. j  a v  a 2 s.  co m
    Runnable listener = new Runnable() {
        @Override
        public void run() {
            try {
                while (!Thread.currentThread().isInterrupted()) {
                    try {
                        Socket socket = serverSocket.accept();
                        socket.setSoTimeout(2000);
                        if (logger.isInfoEnabled()) {
                            logger.info("Starting session with " + socket.getInetAddress().getHostAddress()
                                    + ":" + socket.hashCode());
                        }
                        DummyCimdServer.Session session = new Session(socket);
                        //List<Session> sessions = ...;
                        //sessions.add(session);
                        new Thread(session).start();
                    } catch (SocketException e) {
                        // Ignore, as this was due to #stop
                    }
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    };
    this.thread = new Thread(listener, this.getClass().getName() + "-listener");
    this.thread.start();
}

From source file:org.socsimnet.server.Server.java

@Override
public void run() {
    try {//from   w ww.  j  av  a2 s .  c  o  m
        serverSocket = new ServerSocket(this.port);
        Socket client;
        System.out.println("Server is listening port " + this.port + "...");
        while (!this.stop) {
            try {
                client = serverSocket.accept();
            } catch (SocketException e) {
                break;
            }
            System.out.println("Client accepted " + client.toString() + " hash:" + client.hashCode());
            this.cDB.put(client.hashCode(), client);
            new ClientHandler(this, client).start();
        }
        System.out.println("Server shutting down...");
        printCloseMessage();
        serverSocket.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}