Browse Source

Pull the local UDP port from the ethereal set. The previous
way made the caller specify a local port due to an unusually
persistent bit of ancient lore lodged in my brain.


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

PSp..om 14 years ago
parent
commit
862d2729f8

+ 18 - 35
engine/src/networking/com/jme3/network/Network.java

@@ -115,56 +115,41 @@ public class Network
     
     
     /**
     /**
      *  Creates a Client that communicates with the specified host and port
      *  Creates a Client that communicates with the specified host and port
-     *  using both reliable and fast transports.  The localUdpPort specifies the
-     *  local port to use for listening for incoming 'fast' UDP messages from the
-     *  server.  This port is different than the host port in case the client
-     *  and server are run on the same machine.
+     *  using both reliable and fast transports. 
      */   
      */   
-    public static Client connectToServer( String host, int hostPort, int localUdpPort ) throws IOException
+    public static Client connectToServer( String host, int hostPort ) throws IOException
     {
     {
-        return connectToServer( DEFAULT_GAME_NAME, DEFAULT_VERSION, host, hostPort, hostPort, localUdpPort );   
+        return connectToServer( DEFAULT_GAME_NAME, DEFAULT_VERSION, host, hostPort, hostPort );   
     }
     }
 
 
     /**
     /**
-     *  Creates a Client that communicates with the specified host and port
-     *  using both reliable and fast transports.  The localUdpPort specifies the
-     *  local port to use for listening for incoming 'fast' UDP messages from the
-     *  server.  This port is different than the host port in case the client
-     *  and server are run on the same machine.
+     *  Creates a Client that communicates with the specified host and separate TCP and UDP ports
+     *  using both reliable and fast transports.  
      */   
      */   
-    public static Client connectToServer( String host, int hostPort, int remoteUdpPort, 
-                                          int localUdpPort ) throws IOException
+    public static Client connectToServer( String host, int hostPort, int remoteUdpPort ) throws IOException
     {
     {
-        return connectToServer( DEFAULT_GAME_NAME, DEFAULT_VERSION, host, hostPort, remoteUdpPort,
-                                localUdpPort );
+        return connectToServer( DEFAULT_GAME_NAME, DEFAULT_VERSION, host, hostPort, remoteUdpPort );
     }
     }
 
 
     /**
     /**
      *  Creates a Client that communicates with the specified host and port
      *  Creates a Client that communicates with the specified host and port
-     *  using both reliable and fast transports.  The localUdpPort specifies the
-     *  local port to use for listening for incoming 'fast' UDP messages from the
-     *  server.  This port is different than the host port in case the client
-     *  and server are run on the same machine.
+     *  using both reliable and fast transports.  
      */   
      */   
     public static Client connectToServer( String gameName, int version, 
     public static Client connectToServer( String gameName, int version, 
-                                          String host, int hostPort, int localUdpPort ) throws IOException
+                                          String host, int hostPort ) throws IOException
     {
     {
-        return connectToServer( gameName, version, host, hostPort, hostPort, localUdpPort );   
+        return connectToServer( gameName, version, host, hostPort, hostPort );   
     }
     }
 
 
     /**
     /**
-     *  Creates a Client that communicates with the specified host and port
-     *  using both reliable and fast transports.  The localUdpPort specifies the
-     *  local port to use for listening for incoming 'fast' UDP messages from the
-     *  server.  This port is different than the host port in case the client
-     *  and server are run on the same machine.
+     *  Creates a Client that communicates with the specified host and and separate TCP and UDP ports
+     *  using both reliable and fast transports.  
      */   
      */   
     public static Client connectToServer( String gameName, int version, 
     public static Client connectToServer( String gameName, int version, 
-                                          String host, int hostPort, int remoteUdpPort, 
-                                          int localUdpPort ) throws IOException
+                                          String host, int hostPort, int remoteUdpPort ) throws IOException
     {
     {
         InetAddress remoteAddress = InetAddress.getByName(host);   
         InetAddress remoteAddress = InetAddress.getByName(host);   
-        UdpConnector fast = new UdpConnector( localUdpPort, remoteAddress, remoteUdpPort ); 
+        UdpConnector fast = new UdpConnector( remoteAddress, remoteUdpPort ); 
         SocketConnector reliable = new SocketConnector( remoteAddress, hostPort );        
         SocketConnector reliable = new SocketConnector( remoteAddress, hostPort );        
        
        
         return new DefaultClient( gameName, version, reliable, fast );
         return new DefaultClient( gameName, version, reliable, fast );
@@ -178,16 +163,14 @@ public class Network
             super( gameName, version );
             super( gameName, version );
         }
         }
         
         
-        public void connectToServer( String host, int port, int remoteUdpPort, 
-                                     int localUdpPort ) throws IOException
+        public void connectToServer( String host, int port, int remoteUdpPort ) throws IOException
         {
         {
-            connectToServer( InetAddress.getByName(host), port, remoteUdpPort, localUdpPort );
+            connectToServer( InetAddress.getByName(host), port, remoteUdpPort );
         }                                     
         }                                     
                                  
                                  
-        public void connectToServer( InetAddress address, int port, int remoteUdpPort, 
-                                     int localUdpPort ) throws IOException
+        public void connectToServer( InetAddress address, int port, int remoteUdpPort ) throws IOException
         {
         {
-            UdpConnector fast = new UdpConnector( localUdpPort, address, remoteUdpPort ); 
+            UdpConnector fast = new UdpConnector( address, remoteUdpPort ); 
             SocketConnector reliable = new SocketConnector( address, port );        
             SocketConnector reliable = new SocketConnector( address, port );        
             
             
             setConnectors( reliable, fast );
             setConnectors( reliable, fast );

+ 2 - 4
engine/src/networking/com/jme3/network/NetworkClient.java

@@ -46,10 +46,8 @@ import java.net.InetAddress;
  */
  */
 public interface NetworkClient extends Client
 public interface NetworkClient extends Client
 {
 {
-    public void connectToServer( String host, int port, int remoteUdpPort, 
-                                 int localUdpPort ) throws IOException;
+    public void connectToServer( String host, int port, int remoteUdpPort ) throws IOException;
                                  
                                  
-    public void connectToServer( InetAddress address, int port, int remoteUdpPort, 
-                                 int localUdpPort ) throws IOException;
+    public void connectToServer( InetAddress address, int port, int remoteUdpPort ) throws IOException;
     
     
 }
 }

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

@@ -64,9 +64,9 @@ public class UdpConnector implements Connector
      *  Creates a new UDP connection that send datagrams to the
      *  Creates a new UDP connection that send datagrams to the
      *  specified address and port.
      *  specified address and port.
      */
      */
-    public UdpConnector( int localPort, InetAddress remote, int remotePort ) throws IOException
+    public UdpConnector( InetAddress remote, int remotePort ) throws IOException
     {
     {
-        InetSocketAddress localSocketAddress = new InetSocketAddress(localPort);
+        InetSocketAddress localSocketAddress = new InetSocketAddress(0);
         this.sock = new DatagramSocket( localSocketAddress );
         this.sock = new DatagramSocket( localSocketAddress );
         remoteAddress = new InetSocketAddress( remote, remotePort );
         remoteAddress = new InetSocketAddress( remote, remotePort );