Tuesday, September 28, 2010

Multiplayer Online Gaming - Actionscript and Red Dwarf Server: Part 2

Welcome to Part 2 of my Actionscript and RDS server tutorial series.  In this tutorial I will run through the remaining RDS tutorials leading up to the client/server tutorial where I will subsitute a Flash client.


Lesson Two: Hello Logger!
Create a new java project called tutorial2 and dont forget to add the the sgs-server-api-0.10.1.jar reference library.


Add the code from the tutorial folder ( C:\projects\rds\sgs-server-dist-0.10.1\tutorial\src\com\sun\sgs\tutorial\server\lesson2 )


Copy over the META-INF folder and edit the app.properties for the HelloLogger name and listener properties.

 com.sun.sgs.app.name = HelloLogger  
 com.sun.sgs.app.listener = com.sun.sgs.tutorial.server.lesson2.HelloLogger  
 com.sun.sgs.impl.transport.tcp.listen.port=1139 

Build the Fat Jar, and either copy it into the RDS deploy folder or edit the sgs-boot.properties.  Run the "launch_clean.bat" and you should see the following:




Lesson Three: Tasks, Managers, and Hello Timer!
At this point I think you should have the hang of setting up these lessons, its more of the same again.  The result of this tutorial should look something like this:




Lesson 4: Hello Persistence!
This tutorial is a 3 parter, and its demonstrating persistence, something that my handy batch script is obliterating.  So, for this tutorial we will need a second batch script that doesnt wipe the backing database every time we start the server.  Go ahead and follow the same proceedure to create "launch_standard.bat".  This batch file contains only the second line of the "launch_clean.bat".


 java -jar C:\projects\rds\sgs-server-dist-0.10.1\bin\sgs-boot.jar  


Use the launch_clean script the first time you run each tutorial and then launch_standard to observe persistence.


The rest of this tutorial is straight forward enough.  You will have to juggle the app.properties as you add multiple versions of the HelloPersistence class, but other than that just remember to rebuild the jar each time.


Lesson 5: Hello User!


Ok, now we are getting past the super simple examples and moving on to network connectivity.  This tutorial requires a client as well as a server.  The java client can be found here:
sgs-c-client-dist-0.10.1.zip

For this tutorial you will need to make two projects, one for the client and one for the server.  The server follows the same setup as the last several lessons.  Once you have the server up and running, a client will be needed to make it work.


For the client, create another project "tutorial5_client".  You will need to add a different set of external jar libraries for the client.  Navigate to your c:\projects\rds\sgs-client-0.10.1\lib folder and just grab everything in the folder.  You wont need the META-INF folder used on the server.  Create the HelloUserClient class based off the sample code found in :\projects\rds\sgs-client-0.10.1\tutorial\src\com\sun\sgs\tutorial\client\lesson1


Once the client is ready, start the server via the normal script.  Then start the client through the Eclipse IDE, choosing to run the application as a Java Application.  See the image below:




You should get a result that looks like this:



The rest of the client tutorial should be straight forward, its just improving the server's layout but the setup is more of the same stuff.  Create your classes, modify your app.properties, recompile the fat jar and you should be good to go.


The HelloEcho lesson is fun to finally input some data and see the server send it right back.


Lesson 6: Hello Channels!


Well finally we are at the last lesson in the document.  This one is very similar to the last lesson, it will need a client and a server project.  Go ahead and implement it and see the channels in action.  The only slightly tricky part to this one is that the client includes the HelloUserClient class from Lesson 5, which isnt in the tutorial 6 folder.  Just grab it from your tutorial 5 client and the client should build.


Here is a look at the finished product:






Its important not to skip this lesson because in the next part of my tutorial I will be demonstrating this same server code with a Actionscript client.


Ready for more?  Click here for part 3

No comments:

Post a Comment