How to get the remote host from a rsocket

288 Views Asked by At

I now receive an rsocket connection in my spring project, and then I want to get its remote address and port, how should I get it?Similar to using socket.getRemoteSocketAddress() to get the remote address of the socket.

@ConnectMapping
public void connectMapping(RSocketRequester requester) {
    // there is a resockt connect, how can i get the remote host from it
    RSocket rSocket = requester.rsocket();
    // TODO
    logger.info("host port");
}
1

There are 1 best solutions below

1
On

Unfortunately, I think even if you grab the RSocketRequester in @ConnectMapping or @MessageMapping method it is an internal detail. io.rsocket.core.RSocketRequester via RequesterResponderSupport holds the DuplexConnection which represents a connection over tcp, web socket or in-process. It is not exposed via a public API.

This is a worthy request but you will need to file a feature request to get this added unless I'm missing something obvious.

It isn't clear that there is a hook in https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/api/org/springframework/boot/rsocket/server/RSocketServerCustomizer.html to let you see the DuplexConnection (tcp or web socket etc) as it's established.