Skip to content

Provide a mechanism to provide information about the underlying connection object #25

@yaronyg

Description

@yaronyg

TJWS is built on top of serverSocket which returns a lot of critical information about the underlying connection the server is listening on. The only problem is that if someone messes around with the serverSocket class they can really screw things up.

So minimally I think we should just return the serverSocket but ideally we would wrap it in a protector to keep people from hurting themselves. I defined a class for this purpose given below.

We would also need to edit ListServer to expose an interface to expose this object.

package com.couchbase.lite.listener;

import java.net.InetAddress;
import java.net.ServerSocket;

/**
 * Provides read only status on a socket.
 */
public class SocketStatus {
    protected ServerSocket serverSocket;

    public SocketStatus(ServerSocket serverSocket) {
        this.serverSocket = serverSocket;
    }

    /**
     * Returns the port the acceptor has bound to.
     * @return
     */
    public int getPort() {
        return serverSocket.getLocalPort();
    }

    /**
     * Returns the local IP address of the server socket or null if not bound.
     * @return
     */
    public InetAddress getInetAddress() {
        return serverSocket.getInetAddress();
    }

    /**
     * Returns if the server is bound to a local address and port
     * @return
     */
    public boolean isBound() {
        return serverSocket.isBound();
    }

    /**
     * Returns if the socket the server is listening on is closed
     * @return
     */
    public boolean isClosed() {
        return serverSocket.isClosed();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions