Tutorial: Hello World

Source File: see HelloWorld.java in examples/rooms/.
This tutorial demonstrates a simple Room which broadcasts the message "Hello World" to each Client that connects.

Building the Room

Every Room must implement the RoomListener interface so that our Room can receive event notifications.

public class HelloWorld implements RoomListener {

The only method we care about is onAddClient which is fired when a new Client joins the Room. When this method is called the ClientServices for the Client that joined is also passed. We'll use the ClientServices to send a message to the Client.

    public void onAddClient(ClientServices client) {
        // --- send the message when a Client connects
        client.broadcastClient("Hello World");
    }
    

Deploying the Room

Ensure the example_rooms.jar file that came with the Server is in the ./rooms directory.

Edit uconfig.xml and add the Class under the TYPE element so that we can deploy HelloWorld type Rooms. Then add an instance of HelloWorld under the instances element.
<UNITY>
    <SERVER>
        <SERVER_PORT>9100</SERVER_PORT>
        <ADMIN_PORT>9101</ADMIN_PORT>
        <ADMIN_PASSWORD>password</ADMIN_PASSWORD>
    </SERVER>
    <TYPES>
       <ROOM>
            <ID>HelloWorld</ID>
            <CLASS>org.moock.unity.examples.rooms.HelloWorld</CLASS>
        </ROOM>
    </TYPES>  
    <INSTANCES> 
        <ROOM>
            <ID>helloWorld</ID>
            <TYPE_ID>HelloWorld</TYPE_ID>
        </ROOM>
    </INSTANCES>  
</UNITY>