rev: 23may09

Plan 2

Plan 2: Compile my own Client to print out messages in raw form
NOTE: One BIG item missing in all this is a BUILD discussion or example. One with Maven would be nice or straight java commands, or NetBeans even.

From Library area on main web site

Project Darkstar Hands-On Lab  link to instructions and download  Developers  May 2008
This Hands-on Lab introduces programming game servers using Project Darkstar from Sun Labs. It steps attendees through the construction of a simple textual Multi-User Dungeon (MUD)
Author(s): Jeff Kesselman, Dan Templeton
Keywords: JavaOne 2008, how-to, tutorial
Downloaded lab to Windows machine and opened the index.html file.
Plan 2 Changed to working through the JavaOne 7400 Lab and build a text based MUD.

Exercise 0: Info

Exercise 1: Follow steps 1: 1-4 for NetBeans 6.5
To resolve import errors, had to add to Libraries
also added
to be able to look at source code.

Many errors is source code
(see fixes doc)

Ex1: Step 2 read Lesson and Tutorials again.
Replace pieces of code in with code from
Convert byte[] to ByteBuffer to send massages.
Add sendMessage also.
Build successful..woo hoo.
Try to run
    java.lang.NoClassDefFoundError: com/sun/sgs/impl/kernel/Kernel
Try adding sgs-server-0.9.9.jar to Libraries
Better, errors..don't have database??..try clean build from new NetBeans project.

ref1: Server API Programming Guide.pdf "Project Darkstar Server Application Tutorial 03/18/09"
NetBeans 6.5
File: New Project
    1. Choose Project: Java: Java Class Library
    2. Name and Location: myDarkMUD
        Project Locaton: C:\DATA\GameDevelopment\myDarkMUD
        Project Folder: C:\DATA\GameDevelopment\myDarkMUD\myDarkMUD
ref1 pg9:  "... API classes are in* package." Nice, but which *.jar???
Found in sgs-serverapi-0.9.9.jar. So, RMC Libraries->Add Jar/Folder... and browse to where Darkstar server lib is and add sgs-serverapi-0.9.9.jar to Libraries. Used Relative Path.
Next, RMC Source Pakages->New->Java Package to add a folder named com.sun.sgs.darkmud so the packages will match up with the source code from the 7400 DarkMud example.
Next, copy file from 7400 Darkmud into the package. errors..good sign.
Build MyDarkMUD far so good.
Results in
Copy this file into sgs-server-dist-0.9.9\deploy folder just like for the tutorial.
Go to tutorial\conf\ and copy and edit:
    HelloWorld.boot to myDarkMUD.boot
        Change SGS_PROPERTIES to use file. to
        Change to use myDarkMUD instead of HelloWorld
        Change .app.root to use myDarkMUD instead of HelloWorld
            This seems to set up the database automatically.
        Change .app.listener to use myDarkMUD instead of HelloWorld
opps..Refactor to so that the *.jar filename matches the class...rebuild..then copy into deploy folder to replace first jar file.
ref1 pg 14: Open a command line window and run server using
    java -jar bin/sgs-boot.jar tutorial/conf/myDarkMUD.boot
from the server distribution directory..mine is at
can't find myDarkMUD class..did make a db folder though.
oops..change .app.listener to com.sun.sgs.darkmud.myDarkMUD..still no class
hmm..copy in file and rebuild..copy jar file into class
hmm..recall reading file comments on SGS_DEPLOY's set to  =${SGS_HOME}/tutorial
hmm..copy myDarkMUD.jar into tutorial directory where tutorial.jar is..AH hA..seems to work.
ref plan 1: client launch
Bring up simple client with another Command window and cd to the client tutorial and use
    java -cp tutorial-client.jar;../lib/sgs-client.jar com.sun.sgs.tutorial.client.lesson1.HelloUserClient
Woo Hoo ..client logs in!!!..but nothing else happens..BUT, we can compile and run..
Edit code to output output..error on .impl type classes in Library
Add sgs-server-0.9.9.jar to Libraries..rebuild..still errors when client connects.
Try using most of HelloEchoSessionListener code from ref1 pg 36-37
hmm..didn't like the private static final long serialVersionUID = 1L; entry..comment out...delete db folder..helped..but Kernel problem
Had to rewrite the code to use referenced objects for the session..
Basically replaced SimpleListener method with

    public SimpleListener(ClientSession session) {
        if (session == null) {
            throw new NullPointerException("null session");
        sessionRef = AppContext.getDataManager().createReference(session);
        sessionName = session.getName();
to use referenced for session
then a simple
    public void receivedMessage(ByteBuffer message) {
        ClientSession session = getSession();
was used to echo back anything the user sent.
Plan 2 Exercise 1 part 1: successful...can compile and run server using NetBeans and command line. And use SimpleClient.
Now to fix JavaOne logs in, but error when receiving messages or trying to send.

Load up 7400_Darkstar project. It sets the client as the main class. So just compile and run project.
Logged in at server messages..error message is

May 20, 2009 8:33:14 PM com.sun.sgs.client.simple.SimpleClient$SimpleClientConnectionListener handleSessionMessage
WARNING: SimpleClientListener.receivedMessage callback throws
        at java.nio.ByteBuffer.array(
        at com.sun.sgs.darkmud.client.MudClient.receivedMessage(
so probably ByteBuffer / byte[ ] problem.
try fixing with
    public void receivedMessage(ByteBuffer m) {
//        byte[] message = m.array();
//        String msg = new String(message);
        String msg = new String(m.array());
        appendOutput(msg, Flag.OUTPUT);
build and run..same error..maybe the class has changed..go read API docs on SimpleClientListener
hmm..receivedMessage inherited from interface com.sun.sgs.client.ServerSessionListener..looks ok..but read-only exeption??
Try copying message to new buffer..ah fixed it with
    public void receivedMessage(ByteBuffer m) {
        byte[] message = new byte[m.capacity()];
        String msg = new String(message);
        appendOutput(msg, Flag.OUTPUT);
Client now recieves server message and echo backs..Plan 2 Exercise 1: done..both DarkMUD server and DarkMUD client up
An IDEA..should be able to run the server out of the 7400_Darkstar.jar file by setting the boot properties..
Porting code from into in 7400 project.
Making 7400_Darkstar.boot and .properties files..copy and edit myDarkMUD files
Simple replace except for
which should be the entry class.
Now use
    java -jar bin/sgs-boot.jar tutorial/conf/7400_Darkstar.boot
to start server...looks good..and run client from NetBeans 7400 project..Woo Hoo..logs in..and echos.
Can now use NetBean for all dev work..just copy jar file to server area and run from command line, the run client from NetBeans.
myDarkMUD project no longer needed.