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

Content deleted Content added
imported>SimonSmall
Added page
imported>SimonSmall
Updated explanation
Line 1:
= Summary =
 
This is an example that creates a server and client, sending messages between client and server and back again. NoneThe ofserver the interaction can be modified byis the user.process There are quite a few elements to this,with which is quite a complex process from a code point of view. Much ofall the processingclient is handled by the Marauroaprocesses enginecommunicate. There is noalways needone to worry about this at this stage. You may not fully understand what is happeningserver; thiswe explanationare iscurrently intendedusing toone guideclient, yourunning throughon the functionalitysame we have developed so far, notmachine as athe detailed guide to theserver Marauroafor enginenow.
 
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.
 
= Server =
 
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).
 
== World.java ==
 
The World definitionclass 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.
 
== Rule.java ==
Line 15 ⟶ 19:
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,. andExtra code is needed to createprevent completecompilation codewarnings. Key actions are to create a new account, create a new character and to add the client message to the zone. TheseThe processclient thosewill request these actions when receivedit fromis thecoded to do so. The client cannot request an action that has not been included in the rule processor or its parent class IRPRuleProcessor.
 
= Client =
 
When a client is started it calls the Test class main method.
== 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 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 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, 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''').
 
== 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 createsperforms a login and selects the character, also creating an account if three parameters are given,. performsThe Test client sends a logintext message, and selectschecks theif characternew messages are available. The Testmessages clientreceived thenfrom sendsthe server, saved by the Client class in a textqueue message(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. The messages received from the server, saved by the Client class in a queue (quotes), are printed to the client window.
 
[[Category: NetBeans]]
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).