java.lang.Objectobjectdraw.Network
public class Network
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.
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 |
---|
public Network()
Method Detail |
---|
public static void configure(String game, ServerListener server, ClientListener client)
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.public static void connectToServer(String address, String name)
address
- IP address (in the form "XX.XX.XX.XX") or machine name (in
the form "www.zahniser.net") of servername
- Client namepublic static void openHostDialog()
public static void openJoinDialog()
public static void setGamePort(int port)
port
- public static void setLobbyAddress(String address)
address
- Class D IP address for the multicast grouppublic static void setLobbyPort(int port)
port
- public static void startServer(String name)
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()
.
name
- Server name