objectdraw
Class Network

java.lang.Object
  extended by objectdraw.Network

public class Network
extends Object

The Network class will allow you to set up networked communication between copies of your program running on different computers on a local area network (LAN). You will always have to call Network.configure() in order to specify how the client and server should run. You might use startServer() or joinServer() if you had a game running on a web server. You should probably never use the other methods.

Author:
Russell Zahniser (russell@zahniser.net)

Constructor Summary
Network()
           
 
Method Summary
static void configure(String game, ServerListener server, ClientListener client)
          Configure the parameters that will make it possible for this program to play against other copies of itself over a network.
static void connectToServer(String address, String name)
          Connect to a server at a particular IP address.
static void openHostDialog()
          This is a way for your program to automatically open the "Host network game" dialog, for those who are too cool to use the menus.
static void openJoinDialog()
          This is a way for your program to automatically open the "Join network game" dialog, for those who are too cool to use the menus.
static void setGamePort(int port)
          Set which port the game should use.
static void setLobbyAddress(String address)
          Set the IP address of the UDP multicast group used to discover active games when someone wants to join a game.
static void setLobbyPort(int port)
          Set which port is used for the UPD multicast that identifies active games for someone to join.
static void startServer(String name)
          Have this program start up a game server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Network

public Network()
Method Detail

configure

public static void configure(String game,
                             ServerListener server,
                             ClientListener client)
Configure the parameters that will make it possible for this program to play against other copies of itself over a network. Once this method has been called, the Network menu will show up in your ObjectDraw windows.

As a general rule, this method should be called once, and only once, as soon as possible after your program starts (anywhere in the begin() method is fine). If you reconfigure the server in between creating a server and a client, they won't be able to talk to each other properly, so setting the configuration once and then not messing with it again is the best policy.

Please note that networking is not possible with applets, only Java applications - that is, programs that have a main() method.

Parameters:
game - Unique name for this game that identifies this particular program. This will prevent someone from accidentally connecting to a different game that doesn't know how to respond.
server - Object that will deal with the server side of the program. If you just want the server to take each message that it gets and repeat it back to all the clients, you can use ServerListener.ECHO. Otherwise, you should have some class of your own implement ServerListener.
client - Object that will deal with the client side of the program. Often this will be your WindowController; you can just declare it to implement ClientListener and then have the client methods draw things on the canvas.

connectToServer

public static void connectToServer(String address,
                                   String name)
Connect to a server at a particular IP address. This might be used if you have a server running on a web server at a known address on the internet.

Parameters:
address - IP address (in the form "XX.XX.XX.XX") or machine name (in the form "www.zahniser.net") of server
name - Client name

openHostDialog

public static void openHostDialog()
This is a way for your program to automatically open the "Host network game" dialog, for those who are too cool to use the menus.


openJoinDialog

public static void openJoinDialog()
This is a way for your program to automatically open the "Join network game" dialog, for those who are too cool to use the menus.


setGamePort

public static void setGamePort(int port)
Set which port the game should use. If you need to change this, it probably means you are on a system with a restrictive firewall in place, and it ought to also mean that you have some clue what you're doing. The default port is 21504.

Parameters:
port -

setLobbyAddress

public static void setLobbyAddress(String address)
Set the IP address of the UDP multicast group used to discover active games when someone wants to join a game. You will hopefully never need to mess with this. If you are having trouble getting your program to connect over your LAN, messing with this is not the solution - configuring your computer's firewall is. The default address is 239.255.15.4.

Parameters:
address - Class D IP address for the multicast group

setLobbyPort

public static void setLobbyPort(int port)
Set which port is used for the UPD multicast that identifies active games for someone to join. If you need to change this, it probably means you are on a system with a restrictive firewall in place, and it ought to also mean that you have some clue what you're doing. The default port is 21504.

Parameters:
port -

startServer

public static void startServer(String name)
Have this program start up a game server. The name given will show up in the list under the "Join network game" menu option. This method may only be called after you have done Network.configure().

Parameters:
name - Server name