Skip to content

StandardWebSocketClient providing inaccurate LocalAddress #22395

@ahasbini

Description

@ahasbini

Hello, I'm trying to develop a Spring based server that connects to another WebSocket Server using the classes StandardWebSocketClient and WebSocketConnectionManager.

Sample code below:

String webSocketServerUrl = "ws://someserver:9999/somepath";
WebSocketConnectionManager connectionManager = new WebSocketConnectionManager(
                new StandardWebSocketClient(), MyWebSocketHandler.this, webSocketServerUrl);
connectionManager.start();

Where MyWebSocketHandler has the method afterConnectionEstablished overridden as such:

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
    logger.info("afterConnectionEstablished: outgoing session started {}",
            session.getLocalAddress());

The output of the log is as such:

afterConnectionEstablished: outgoing session started AHASBINI-PC/192.168.99.1:9999

When in fact I check my connections on my PC using tools and commands such as netstat -abn or netstat -apn and find out that the local connection is not from port 9999 but from a different port completely. I've traced the creation of the session to below lines found in StandardWebSocketClient.

@Override
protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
HttpHeaders headers, final URI uri, List<String> protocols,
List<WebSocketExtension> extensions, Map<String, Object> attributes) {
int port = getPort(uri);
InetSocketAddress localAddress = new InetSocketAddress(getLocalHost(), port);
InetSocketAddress remoteAddress = new InetSocketAddress(uri.getHost(), port);
final StandardWebSocketSession session = new StandardWebSocketSession(headers,
attributes, localAddress, remoteAddress);

Apparently it's setting the remote port and local port to the same value of the WebSocket Server URI.

However on the WebSocket Server which is receiving the connection via the apache Tomcat container and is also a Spring based implementation, the value of the remote and local ports are correct and not equal to each other within the WebSocketSession.

Thanks :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions