Chat Tutorial in NetBeans/Text Client explanation
This is an example that creates a server and client, sending messages between client and server and back again. The server is the process with which all the client processes communicate. There is always one server; we are currently using one client, running on the same machine as the server for now.
None of the interaction can be modified by the user. There are quite a few elements to this, which is quite a complex process from a code point of view. Much of the processing is handled by the Marauroa engine. You may not fully understand what is happening; this explanation is intended to guide you through the functionality we have developed so far, not as a detailed guide to the Marauroa engine.
However, if this communication cannot be established there is little point continuing further. Despite the apparent lack of functionality for the user, this is a major achievement.
When the server is started, it loads some configuration information from the server.ini file. This defines which database to use and where it is stored, the communication port and the name of the world and ruleprocessor classes. These two classes define what the server "knows about". The server.ini file is given as a parameter to the start command (so alternative configurations could be used).
The World class creates the contents of the game world. A world can be separated into one or more Zones; each being independent of other zones. In this example, there is only one zone, which is added to the world when the server starts. Messages are added as objects to the World when received from the client.
The server and client interact through the use of messages; the client sends a message to the server about what it wants to do (an Action), the server processes that action and sends a message back to the client about what has changed (a Perception). The Server Manager cannot receive messages directly; they are passed through the Rule Processor so that the requested actions can be filtered or modified to provide the correct requests to the Server Manager.
We have a simple Rule Processor that contains a few actions. Extra code is needed to prevent compilation warnings. Key actions are to create a new account, create a new character and to add the client message to the zone. The client will request these actions when it is coded to do so. The client cannot request an action that has not been included in the rule processor or its parent class IRPRuleProcessor.
When a client is started it calls the Test class main method.
The client code handles communications with the server. It does not do much so far; it gets a list of user characters (at the moment there is one character per user), and handles the messaging to and from the server.
The message sent in the Test class is converted into an action and sent to the server, where it is converted to an object. The perception handler updates the clients view of the world objects. A message received from the server is formatted and added to the queue (object quotes).
The Test class contains the main method, so this runs on starting the client process. The first step is to connect the client to the server; for this example, the server name and port are specified in the code and cannot be changed. The client performs a login and selects the character, also creating an account if three parameters are given. The Test client sends a text message, and checks if new messages are available. The messages received from the server, saved by the Client class in a queue (object quotes), are printed to the client window. It waits five seconds (50 x 100 milliseconds), and sends another message. This repeats forever every 10 seconds, until the user interrupts the client or an error occurs.