From fd62579bf3e65ffb267081547b0d69433cbd991b Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Sat, 19 Mar 2011 02:34:48 +0000 Subject: [PATCH] Added a String getAddress() to the server-side connection stuff... this will be useful for certain types of filtering and is good for informational logging. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7030 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../networking/com/jme3/network/HostedConnection.java | 10 +++++++++- .../com/jme3/network/base/DefaultServer.java | 7 ++++++- .../networking/com/jme3/network/kernel/Endpoint.java | 7 +++++++ .../com/jme3/network/kernel/tcp/NioEndpoint.java | 5 +++++ .../com/jme3/network/kernel/udp/UdpEndpoint.java | 5 +++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/engine/src/networking/com/jme3/network/HostedConnection.java b/engine/src/networking/com/jme3/network/HostedConnection.java index 0e06783ed..8c8e50e15 100644 --- a/engine/src/networking/com/jme3/network/HostedConnection.java +++ b/engine/src/networking/com/jme3/network/HostedConnection.java @@ -47,7 +47,15 @@ public interface HostedConnection extends MessageConnection * Returns the server-unique ID for this client. */ public int getId(); - + + /** + * Returns the transport specific remote address of this connection + * as a string. This may or may not be unique per connection depending + * on the type of transport. It is provided for information and filtering + * purposes. + */ + public String getAddress(); + /** * Closes and removes this connection from the server * sending the optional reason to the remote client. diff --git a/engine/src/networking/com/jme3/network/base/DefaultServer.java b/engine/src/networking/com/jme3/network/base/DefaultServer.java index 0328134ae..a15fc7d15 100644 --- a/engine/src/networking/com/jme3/network/base/DefaultServer.java +++ b/engine/src/networking/com/jme3/network/base/DefaultServer.java @@ -352,7 +352,12 @@ public class DefaultServer implements Server { return id; } - + + public String getAddress() + { + return reliable == null ? null : reliable.getAddress(); + } + public void send( Message message ) { ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null); diff --git a/engine/src/networking/com/jme3/network/kernel/Endpoint.java b/engine/src/networking/com/jme3/network/kernel/Endpoint.java index 56a3d5463..67dde8739 100644 --- a/engine/src/networking/com/jme3/network/kernel/Endpoint.java +++ b/engine/src/networking/com/jme3/network/kernel/Endpoint.java @@ -49,6 +49,13 @@ public interface Endpoint */ public long getId(); + /** + * Returns the transport specific remote address of this endpoint + * as a string. This may or may not be unique per endpoint depending + * on the type of transport. + */ + public String getAddress(); + /** * Returns the kernel to which this endpoint belongs. */ diff --git a/engine/src/networking/com/jme3/network/kernel/tcp/NioEndpoint.java b/engine/src/networking/com/jme3/network/kernel/tcp/NioEndpoint.java index 3e391e85d..e51363e81 100644 --- a/engine/src/networking/com/jme3/network/kernel/tcp/NioEndpoint.java +++ b/engine/src/networking/com/jme3/network/kernel/tcp/NioEndpoint.java @@ -81,6 +81,11 @@ public class NioEndpoint implements Endpoint return id; } + public String getAddress() + { + return String.valueOf(socket.socket().getRemoteSocketAddress()); + } + public boolean isConnected() { return socket.isConnected(); diff --git a/engine/src/networking/com/jme3/network/kernel/udp/UdpEndpoint.java b/engine/src/networking/com/jme3/network/kernel/udp/UdpEndpoint.java index 6228e13d2..9b72e66cd 100644 --- a/engine/src/networking/com/jme3/network/kernel/udp/UdpEndpoint.java +++ b/engine/src/networking/com/jme3/network/kernel/udp/UdpEndpoint.java @@ -86,6 +86,11 @@ public class UdpEndpoint implements Endpoint return id; } + public String getAddress() + { + return String.valueOf(address); + } + public boolean isConnected() { return socket.isConnected();