OSDN Git Service

Leave the client UDP connection 'connectionless' and
authorPSpeed42@gmail.com <PSpeed42@gmail.com@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sat, 19 Mar 2011 06:24:28 +0000 (06:24 +0000)
committerPSpeed42@gmail.com <PSpeed42@gmail.com@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sat, 19 Mar 2011 06:24:28 +0000 (06:24 +0000)
left a really big comment as to why.  It's sort of
too bad but not that big of a deal.

Now clients can connect to 'localhost' and still
receive UDP packets.

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7035 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

engine/src/networking/com/jme3/network/kernel/udp/UdpConnector.java

index 97a2e5e..982fd1d 100644 (file)
@@ -71,8 +71,22 @@ public class UdpConnector implements Connector
         remoteAddress = new InetSocketAddress( remote, remotePort );
         
         // Setup to receive only from the remote address
-        sock.connect( remoteAddress );
-        
+        //sock.connect( remoteAddress );
+        //
+        // The above is a really nice idea since it means that we
+        // wouldn't get random datagram packets from anything that
+        // happened to send garbage to our UDP port.  The problem is
+        // when connecting to a server at "localhost" because "localhost"
+        // will/should always resolve to 127.0.0.1... but the server
+        // doesn't send packets from 127.0.0.1 because it's listening
+        // on the real interface.  And that doesn't match and this end
+        // rejects them.
+        //
+        // This means at some point the read() code will need to validate
+        // that the packets came from the real server before parsing them.
+        // Otherwise we likely throw random deserialization errors and kill
+        // the client.  Which may or may not warrant extra code below.  <shrug>
         connected.set(true);
     }