Chat Tutorial in NetBeans/Text Client explanation: Difference between revisions

From Arianne
Jump to navigation Jump to search
imported>SimonSmall
Added page
imported>SimonSmall
Added page
(No difference)

Revision as of 10:40, 21 January 2012

Summary

This is an example that creates a server and client, sending messages between client and server and back again. 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. There is no need to worry about this at this stage. 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.

Server

World.java

The World definition creates 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.

Rule.java

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, and code needed to create complete code. Key actions are to create a new account, create a new character and to add the client message to the zone. These process those actions when received from the client.

Client

Test.java

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 creates an account if three parameters are given, performs a login and selects the character. The Test client then sends a text message, waits five seconds (50 x 100 milliseconds), and sends another message. This repeats forever, until the user interrupts the client or an error occurs. The messages received from the server, saved by the Client class in a queue (quotes), are printed to the client window.

Client.java

The client needs two elements, a list of the known world objects and the processor of received messages (perceptions). Other parts of the code are needed to create complete code, but are not important in this example.

The message sent in the Test class is converted into an action and sent to the server. The perception handler updates the clients view of the world objects. A message received from the server is formatted and added to the queue (quotes).