The Session is the correct place to start.

Using Session.getRemoteAddress()
<http://download.eclipse.org/jetty/9.3.9.v20160517/apidocs/org/eclipse/jetty/websocket/api/Session.html#getRemoteAddress-->
returns a java.net.InetSocketAddress
<http://docs.oracle.com/javase/8/docs/api/java/net/InetSocketAddress.html>
which is the appropriate thing to return.

After that, you are in the world of Java networking, and all that it
implies.
Note that the InetSocketAddress can be an IPv4 or IPv6 address.

Testing for (session != null) is appropriate in many places.
But seeing as you didn't  specify where you are doing this, its hard to be
more precise.

If you decide to pull the remote address during onWebSocketConnect() then
its safe to skip the session != null check.

(hmm, not sure what would happen if the websocket was extremely short lived)


Joakim Erdfelt / [email protected]

On Tue, Jun 14, 2016 at 6:18 AM, Alexander Farber <
[email protected]> wrote:

> Hello, would calling
>
>     String ip = mSession.getRemoteAddress().getAddress().getHostAddress();
>
> be a good way of getting the remote IP address in the onWebSocketText
> callback of a custom WebSocketListener implementation?
>
> I am asking because -
>
> 1) Is calling 3 methods necessary or maybe there is a shortcut?
>
> 2) Should (mSession != null) be checked first as in the example
>
>
> http://www.eclipse.org/jetty/documentation/current/jetty-websocket-api-listener.html
> ?
>
> Thank you
> Alex
>
>
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to