Search in sources :

Example 1 with ClientContext

use of com.robo4j.socket.http.units.ClientContext in project robo4j by Robo4J.

the class ChannelUtils method getSocketAddressByContext.

public static SocketAddress getSocketAddressByContext(SocketContext<?> context) {
    if (context instanceof ClientContext) {
        final String clientHost = context.getPropertySafe(String.class, PROPERTY_HOST);
        final int clientPort = context.getPropertySafe(Integer.class, PROPERTY_SOCKET_PORT);
        return new InetSocketAddress(clientHost, clientPort);
    } else if (context instanceof ServerContext) {
        final int serverPort = context.getPropertySafe(Integer.class, PROPERTY_SOCKET_PORT);
        return new InetSocketAddress(serverPort);
    } else {
        throw new SocketException("invalid context" + context);
    }
}
Also used : SocketException(com.robo4j.socket.http.SocketException) ServerContext(com.robo4j.socket.http.units.ServerContext) InetSocketAddress(java.net.InetSocketAddress) ClientContext(com.robo4j.socket.http.units.ClientContext)

Aggregations

SocketException (com.robo4j.socket.http.SocketException)1 ClientContext (com.robo4j.socket.http.units.ClientContext)1 ServerContext (com.robo4j.socket.http.units.ServerContext)1 InetSocketAddress (java.net.InetSocketAddress)1