Better address binding.
Deprecated the methods on the old Message class that are truly dangerous in the new version since they always return null. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7016 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
		
							parent
							
								
									24b65c4914
								
							
						
					
					
						commit
						d1c8626419
					
				| @ -57,11 +57,21 @@ public class Network | ||||
|      *  will be used for both TCP and UDP communication. | ||||
|      */ | ||||
|     public static Server createServer( int port ) throws IOException | ||||
|     {    | ||||
|         return createServer( port, port ); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      *  Creates a Server that will utilize both reliable and fast | ||||
|      *  transports to communicate with clients.  The specified port | ||||
|      *  will be used for both TCP and UDP communication. | ||||
|      */ | ||||
|     public static Server createServer( int tcpPort, int udpPort ) throws IOException | ||||
|     { | ||||
|         InetAddress local = InetAddress.getLocalHost(); | ||||
|         //InetAddress local = InetAddress.getLocalHost(); | ||||
|          | ||||
|         UdpKernel fast = new UdpKernel(local, port); | ||||
|         SelectorKernel reliable = new SelectorKernel(local,port); | ||||
|         UdpKernel fast = new UdpKernel(udpPort); | ||||
|         SelectorKernel reliable = new SelectorKernel(tcpPort); | ||||
|   | ||||
|         return new DefaultServer( reliable, fast );        | ||||
|     } | ||||
|  | ||||
| @ -54,21 +54,24 @@ import com.jme3.network.kernel.*; | ||||
|  */ | ||||
| public class SelectorKernel extends AbstractKernel | ||||
| { | ||||
|     private InetAddress host; | ||||
|     private int port; | ||||
|     private InetSocketAddress address; | ||||
|     private SelectorThread thread; | ||||
| 
 | ||||
|     private Map<Long,NioEndpoint> endpoints = new ConcurrentHashMap<Long,NioEndpoint>(); | ||||
| 
 | ||||
|     public SelectorKernel( InetAddress host, int port ) | ||||
|     { | ||||
|         this.host = host; | ||||
|         this.port = port; | ||||
|         this( new InetSocketAddress(host, port) ); | ||||
|     } | ||||
| 
 | ||||
|     public SelectorKernel( int port ) throws IOException | ||||
|     { | ||||
|         this( InetAddress.getLocalHost(), port ); | ||||
|         this( new InetSocketAddress(port) ); | ||||
|     } | ||||
| 
 | ||||
|     public SelectorKernel( InetSocketAddress address )  | ||||
|     { | ||||
|         this.address = address;    | ||||
|     } | ||||
| 
 | ||||
|     protected SelectorThread createSelectorThread() | ||||
| @ -87,7 +90,7 @@ public class SelectorKernel extends AbstractKernel | ||||
|             thread.connect(); | ||||
|             thread.start(); | ||||
|         } catch( IOException e ) { | ||||
|             throw new KernelException( "Error hosting:" + host + " port:" + port, e ); | ||||
|             throw new KernelException( "Error hosting:" + address, e ); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -100,7 +103,7 @@ public class SelectorKernel extends AbstractKernel | ||||
|             thread.close(); | ||||
|             thread = null; | ||||
|         } catch( IOException e ) { | ||||
|             throw new KernelException( "Error closing host connection:" + host + " port:" + port, e ); | ||||
|             throw new KernelException( "Error closing host connection:" + address, e ); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -205,7 +208,7 @@ public class SelectorKernel extends AbstractKernel | ||||
| 
 | ||||
|         public SelectorThread() | ||||
|         { | ||||
|             setName( "Selector@" + host + ":" + port ); | ||||
|             setName( "Selector@" + address ); | ||||
|             setDaemon(true); | ||||
|         } | ||||
| 
 | ||||
| @ -219,8 +222,7 @@ public class SelectorKernel extends AbstractKernel | ||||
|             serverChannel.configureBlocking(false); | ||||
| 
 | ||||
|             // Bind the server socket to the specified address and port | ||||
|             InetSocketAddress isa = new InetSocketAddress(host, port); | ||||
|             serverChannel.socket().bind(isa); | ||||
|             serverChannel.socket().bind(address); | ||||
| 
 | ||||
|             // Register the server socket channel, indicating an interest in | ||||
|             // accepting new connections | ||||
|  | ||||
| @ -49,8 +49,7 @@ import com.jme3.network.kernel.*; | ||||
|  */ | ||||
| public class UdpKernel extends AbstractKernel | ||||
| { | ||||
|     private InetAddress host; | ||||
|     private int port; | ||||
|     private InetSocketAddress address; | ||||
|     private HostThread thread; | ||||
| 
 | ||||
|     // The nature of UDP means that even through a firewall,  | ||||
| @ -60,13 +59,17 @@ public class UdpKernel extends AbstractKernel | ||||
| 
 | ||||
|     public UdpKernel( InetAddress host, int port ) | ||||
|     { | ||||
|         this.host = host; | ||||
|         this.port = port; | ||||
|         this( new InetSocketAddress(host, port) ); | ||||
|     } | ||||
| 
 | ||||
|     public UdpKernel( int port ) throws IOException | ||||
|     { | ||||
|         this( InetAddress.getLocalHost(), port ); | ||||
|         this( new InetSocketAddress(port) ); | ||||
|     } | ||||
| 
 | ||||
|     public UdpKernel( InetSocketAddress address ) | ||||
|     { | ||||
|         this.address = address; | ||||
|     } | ||||
| 
 | ||||
|     protected HostThread createHostThread() | ||||
| @ -85,7 +88,7 @@ public class UdpKernel extends AbstractKernel | ||||
|             thread.connect(); | ||||
|             thread.start(); | ||||
|         } catch( IOException e ) { | ||||
|             throw new KernelException( "Error hosting:" + host + " port:" + port, e ); | ||||
|             throw new KernelException( "Error hosting:" + address, e ); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -98,7 +101,7 @@ public class UdpKernel extends AbstractKernel | ||||
|             thread.close(); | ||||
|             thread = null; | ||||
|         } catch( IOException e ) { | ||||
|             throw new KernelException( "Error closing host connection:" + host + " port:" + port, e ); | ||||
|             throw new KernelException( "Error closing host connection:" + address, e ); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -170,7 +173,7 @@ public class UdpKernel extends AbstractKernel | ||||
| 
 | ||||
|         public HostThread() | ||||
|         { | ||||
|             setName( "UDP Host@" + host + ":" + port ); | ||||
|             setName( "UDP Host@" + address ); | ||||
|             setDaemon(true); | ||||
|         } | ||||
| 
 | ||||
| @ -181,7 +184,7 @@ public class UdpKernel extends AbstractKernel | ||||
| 
 | ||||
|         public void connect() throws IOException | ||||
|         { | ||||
|             socket = new DatagramSocket( port, host ); | ||||
|             socket = new DatagramSocket( address ); | ||||
|         } | ||||
| 
 | ||||
|         public void close() throws IOException, InterruptedException | ||||
|  | ||||
| @ -65,18 +65,22 @@ public class Message implements com.jme3.network.Message { | ||||
|         return this; | ||||
|     } | ||||
| 
 | ||||
|     @Deprecated | ||||
|     public Client getClient() { | ||||
|         return connector; | ||||
|     } | ||||
| 
 | ||||
|     @Deprecated | ||||
|     public void setClient(Client connector) { | ||||
|         this.connector = connector; | ||||
|     } | ||||
| 
 | ||||
|     @Deprecated | ||||
|     public Connection getConnection() { | ||||
|         return connection; | ||||
|     } | ||||
| 
 | ||||
|     @Deprecated | ||||
|     public void setConnection(Connection connection) { | ||||
|         this.connection = connection; | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user