Added some warning for some odd state issues that can happen

in real life.
Fixed a subtle bug with the UDP endpoints where they weren't
getting propery closed.  This manifested as the endpoints
still getting broadcasts even after Server no longer knew
about them.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7243 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 14 years ago
parent 255fe9f9c9
commit 189a787d36
  1. 4
      engine/src/networking/com/jme3/network/base/KernelAdapter.java
  2. 9
      engine/src/networking/com/jme3/network/kernel/udp/UdpEndpoint.java
  3. 2
      engine/src/networking/com/jme3/network/kernel/udp/UdpKernel.java

@ -142,6 +142,10 @@ public class KernelAdapter extends Thread
try {
HostedConnection source = getConnection(p);
if( source == null ) {
log.log( Level.WARNING, "Recieved message from unconnected endpoint:" + p + " message:" + m );
return;
}
messageDispatcher.messageReceived( source, m );
} catch( Exception e ) {
reportError(e);

@ -53,6 +53,7 @@ public class UdpEndpoint implements Endpoint
private SocketAddress address;
private DatagramSocket socket;
private UdpKernel kernel;
private boolean connected = true; // it's connectionless but we track logical state
public UdpEndpoint( UdpKernel kernel, long id, SocketAddress address, DatagramSocket socket )
{
@ -85,6 +86,7 @@ public class UdpEndpoint implements Endpoint
try {
kernel.closeEndpoint(this);
connected = false;
} catch( IOException e ) {
throw new KernelException( "Error closing endpoint for socket:" + socket, e );
}
@ -102,11 +104,16 @@ public class UdpEndpoint implements Endpoint
public boolean isConnected()
{
return socket.isConnected();
// The socket is always unconnected anyway so we track our
// own logical state for the kernel's benefit.
return connected;
}
public void send( ByteBuffer data )
{
if( !isConnected() ) {
throw new KernelException( "Endpoint is not connected:" + this );
}
try {
DatagramPacket p = new DatagramPacket( data.array(), data.position(),
data.remaining(), address );

@ -128,7 +128,7 @@ public class UdpKernel extends AbstractKernel
// Does it match the filter?
if( filter != null && !filter.apply(p) )
continue;
// Send the data
p.send( data );
}

Loading…
Cancel
Save