Added a connected check to DefaultClient's channel-based

send method.  Even though it delegates to a method that
will wait for being connected, send(channel, msg) can't
properly do its channel verification until the connection
is fully setup.  So now it waits.
I also went ahead and added constants for the normal default
(previouslly hidden) channels that are used during normal
send(msg).  Useful for code that wants to deal with channels
genericly but still wants to be able to use the default
channels.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10837 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
PSp..om 11 years ago
parent db8dc8d4fa
commit a2a39bd0d5
  1. 26
      engine/src/networking/com/jme3/network/MessageConnection.java
  2. 14
      engine/src/networking/com/jme3/network/base/DefaultClient.java
  3. 6
      engine/src/networking/com/jme3/network/base/DefaultServer.java

@ -41,6 +41,32 @@ package com.jme3.network;
*/
public interface MessageConnection
{
/**
* Indicates the default reliable channel that is used
* when calling the channel-less send() with a reliable
* message. This channel number can be used in the send(channel, msg)
* version of send.
*
* <p>Normally, callers should just call the regular non-channel
* send message but these channel numbers are useful for extensions
* that allow the user to specify a channel and want to still
* support the default channels.</p>
*/
public static final int CHANNEL_DEFAULT_RELIABLE = -2;
/**
* Indicates the default unreliable channel that is used
* when calling the channel-less send() with a reliable=false
* message. This channel number can be used in the send(channel, msg)
* version of send.
*
* <p>Normally, callers should just call the regular non-channel
* send message but these channel numbers are useful for extensions
* that allow the user to specify a channel and want to still
* support the default channels.</p>
*/
public static final int CHANNEL_DEFAULT_UNRELIABLE = -1;
/**
* Sends a message to the other end of the connection.
*/

@ -212,9 +212,19 @@ public class DefaultClient implements Client
public void send( int channel, Message message )
{
if( channel < 0 || channel + CH_FIRST >= channels.size() )
if( channel >= 0 ) {
// Make sure we aren't still connecting. Channels
// won't be valid until we are fully connected since
// we receive the channel list from the server.
// The default channels don't require the connection
// to be fully up before sending.
waitForConnected();
}
if( channel < CHANNEL_DEFAULT_RELIABLE || channel + CH_FIRST >= channels.size() ) {
throw new IllegalArgumentException( "Channel is undefined:" + channel );
send( channel + CH_FIRST, message, true );
}
send(channel + CH_FIRST, message, true);
}
protected void send( int channel, Message message, boolean waitForConnected )

@ -143,8 +143,10 @@ public class DefaultServer implements Server
protected void checkChannel( int channel )
{
if( channel < 0 || channel >= alternatePorts.size() )
throw new IllegalArgumentException( "Channel is undefined:" + channel );
if( channel < MessageConnection.CHANNEL_DEFAULT_RELIABLE
|| channel >= alternatePorts.size() ) {
throw new IllegalArgumentException( "Channel is undefined:" + channel );
}
}
public void start()

Loading…
Cancel
Save