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

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

@ -53,6 +53,7 @@ public class UdpEndpoint implements Endpoint
private SocketAddress address; private SocketAddress address;
private DatagramSocket socket; private DatagramSocket socket;
private UdpKernel kernel; 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 ) public UdpEndpoint( UdpKernel kernel, long id, SocketAddress address, DatagramSocket socket )
{ {
@ -85,6 +86,7 @@ public class UdpEndpoint implements Endpoint
try { try {
kernel.closeEndpoint(this); kernel.closeEndpoint(this);
connected = false;
} catch( IOException e ) { } catch( IOException e ) {
throw new KernelException( "Error closing endpoint for socket:" + socket, e ); throw new KernelException( "Error closing endpoint for socket:" + socket, e );
} }
@ -102,11 +104,16 @@ public class UdpEndpoint implements Endpoint
public boolean isConnected() 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 ) public void send( ByteBuffer data )
{ {
if( !isConnected() ) {
throw new KernelException( "Endpoint is not connected:" + this );
}
try { try {
DatagramPacket p = new DatagramPacket( data.array(), data.position(), DatagramPacket p = new DatagramPacket( data.array(), data.position(),
data.remaining(), address ); data.remaining(), address );

Loading…
Cancel
Save