Game Development Reference
In-Depth Information
client.addMessageListener(serverMessageHandler,
ServerMessage.class);
It is also possible to let ServerMessageHandler handle all incoming mes-
sages by using the following line of code:
client.addMessageListener(serverMessageHandler);
4. We now tell the server to create a message and send it to all the players when
someone connects:
ServerMessage connMessage = new ServerMessage();
String message = "Player connected from: " +
conn.getAddress();
connMessage.setMessage(message);
server.broadcast(connMessage);
5. There is one more thing we need to do. All the message classes used need to be
registered before being used. We do this before the application starts, as follows:
public static void main(String[] args ) throws
Exception {
Serializer.registerClass(ServerMessage.class);
Search WWH ::




Custom Search