From 9b5c1bb4d224f7e496c70292bfbb87323d4b59d9 Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Sat, 19 Mar 2011 06:24:28 +0000 Subject: [PATCH] Leave the client UDP connection 'connectionless' and 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: https://jmonkeyengine.googlecode.com/svn/trunk@7035 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3/network/kernel/udp/UdpConnector.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/engine/src/networking/com/jme3/network/kernel/udp/UdpConnector.java b/engine/src/networking/com/jme3/network/kernel/udp/UdpConnector.java index 97a2e5eb6..982fd1dff 100644 --- a/engine/src/networking/com/jme3/network/kernel/udp/UdpConnector.java +++ b/engine/src/networking/com/jme3/network/kernel/udp/UdpConnector.java @@ -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. + connected.set(true); }