SpiderMonkey 0.9 Alpha



And thus it has come this far - I finally feel comfortable with releasing SpiderMonkey 0.9 alpha to you hungry monkeys! I've been working on this for about a month, and I think you'll like what you'll see (and hopefully put it to good use, with my help if necessary).

Get the JAR over at:
http://codeninja.me/SpiderMonkey/SpiderMonkey0.9_Alpha.jar
Source:
http://codeninja.me/SpiderMonkey/SpiderMonkey0.9_src_Alpha.jar
And look into the docs over at
http://codeninja.me/SpiderMonkey/docs/


Update: SpiderMonkey is now a part of the jME3 core. If you have the latest jME3 sources, you have the latest SpiderMonkey. Also see the SpiderMonkey documentation.

I hope you like the release, and please do bring in the bugs. As always I'll try to fix them in one or two days. Have fun!

Cool! We should add this to the jMP contribution repository soon.

Is there a simple client and server code? For the basic setup for it?

Darknet said:
Is there a simple client and server code? For the basic setup for it?

The first tutorial will help you on your way :) https://wiki.jmonkeyengine.org/legacy/doku.php/spidermonkey

Is awsum! :slight_smile:

Would be also good to have some example of server and client integrated in JME3 to see how to implement simple synchronization or synchronization based on some current camera radius or smth. But that is probably more advanced topic and doesn’t concern spidermonkey so much…

Been trying to get a simple server and client working but got error in converting the class object message.

HelloMessage.java



package org.jme3.share;



import me.codeninja.spidermonkey.message.Message;

import me.codeninja.spidermonkey.serializing.Serializable;



@Serializable()

public class HelloMessage extends Message {

public String hello = “Hello!”;

}





TerrainServer.java

package org.jme3.server;



import me.codeninja.spidermonkey.connection.Client;

import me.codeninja.spidermonkey.message.Message;

import com.jme3.material.Material;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.app.SimpleBulletApplication;

import com.jme3.input.controls.ActionListener;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Spatial;

import java.io.IOException;

import java.util.logging.Level;

import java.util.logging.Logger;

import me.codeninja.spidermonkey.connection.Server;

import me.codeninja.spidermonkey.events.ConnectionListener;

import me.codeninja.spidermonkey.events.MessageListener;

import me.codeninja.spidermonkey.serializing.Serializer;

import org.jme3.share.HelloMessage;



public class TerrainServer extends SimpleBulletApplication

implements ActionListener,ConnectionListener, MessageListener {



public Spatial Scene;

public Server server;



public static void main(String[] args)

{

TerrainServer app = new TerrainServer();

app.setShowSettings(false);//disable config for start up

app.start();

}



@Override

public void simpleInitApp() {

flyCam.setMoveSpeed(100);

//Geometry teapot = (Geometry) assetManager.loadModel(“Models/Terraintmp.obj”);

//Material mat = new Material(assetManager, “Common/MatDefs/Misc/WireColor.j3md”);



//teapot.setMaterial(mat);

//rootNode.attachChild(teapot);

initplayer();

initnetwork();

}



public void initnetwork(){

try {

Serializer.registerClass(HelloMessage.class);

server = new Server(4040, 5050);

server.addConnectionListener(this);

server.addMessageListener(this);

server.start();



server.addIndividualMessageListener(HelloMessage.class,this);

System.out.print(“started network”);

} catch (IOException ex) {

Logger.getLogger(TerrainServer.class.getName()).log(Level.SEVERE, null, ex);

System.out.print(“fail network”);

}

}



public void closenetwork(){

try {

server.stop();

} catch (IOException ex) {

System.out.print(“fail closing network”);

}

}



public void initplayer(){

Box b = new Box(Vector3f.ZERO, 1, 1, 1);

Geometry player = new Geometry(“blue cube”, b);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat.setColor(“m_Color”, ColorRGBA.Blue);

player.setMaterial(mat);

rootNode.attachChild(player);

//this enble mouse cursor to show up

flyCam.setDragToRotate(true);

inputManager.setCursorVisible(true);

}



@Override

public void simpleUpdate(float tpf){



}



public void onAction(String string, boolean bln, float f) {

//throw new UnsupportedOperationException(“Not supported yet.”);

}



//server code

//this from implements ConnectionListener, MessageListener

public void clientConnected(Client client) {



}



public void clientDisconnected(Client client) {



}



public void messageReceived(Message message) {

System.out.print(“incoming message”);

// This message is of type HelloMessage, so we don’t have to check.

HelloMessage helloMessage = (HelloMessage) message;

System.out.println(helloMessage.hello);

helloMessage.hello = “Hi!”;

try {

message.getClient().sendTCP(helloMessage);

} catch (IOException ex) {

Logger.getLogger(TerrainServer.class.getName()).log(Level.SEVERE, null, ex);

}



}



public void messageSent(Message msg) {



}



public void objectReceived(Object o) {



}



public void objectSent(Object o) {



}



}







TerrainClient.java

package org.jme3.client;



import me.codeninja.spidermonkey.connection.Client;

import me.codeninja.spidermonkey.message.Message;

import com.jme3.material.Material;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.app.SimpleBulletApplication;

import com.jme3.input.controls.ActionListener;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Spatial;

import java.io.IOException;

import java.util.logging.Level;

import java.util.logging.Logger;

import me.codeninja.spidermonkey.events.ConnectionListener;

import me.codeninja.spidermonkey.events.MessageListener;

import me.codeninja.spidermonkey.serializing.Serializer;

import org.jme3.share.HelloMessage;



public class TerrainClient extends SimpleBulletApplication

implements ActionListener,ConnectionListener, MessageListener {



public Spatial Scene;

Client client;



public static void main(String[] args)

{

TerrainClient app = new TerrainClient();

app.setShowSettings(false);//disable config for start up

app.start();

}



@Override

public void simpleInitApp() {

flyCam.setMoveSpeed(100);

initplayer();

initnetwork();

}



public void initnetwork(){

try {

Serializer.registerClass(HelloMessage.class);

client = new Client(“localhost”, 4040, 5050);

client.addConnectionListener(this);

client.addMessageListener(this);



client.addIndividualMessageListener(HelloMessage.class,this);



client.start();

System.out.print(“started network”);

client.sendTCP(new HelloMessage());

} catch (IOException ex) {

Logger.getLogger(TerrainClient.class.getName()).log(Level.SEVERE, null, ex);

System.out.print(“fail network”);

}

}



public void closenetwork(){

try {

client.disconnect();

} catch (IOException ex) {

System.out.print(“fail closing network”);

}

}



public void initplayer(){

Box b = new Box(Vector3f.ZERO, 1, 1, 1);

Geometry player = new Geometry(“blue cube”, b);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat.setColor(“m_Color”, ColorRGBA.Blue);

player.setMaterial(mat);

rootNode.attachChild(player);

//this enble mouse cursor to show up

flyCam.setDragToRotate(true);

inputManager.setCursorVisible(true);

}



@Override

public void simpleUpdate(float tpf){



}



public void onAction(String string, boolean bln, float f) {

//throw new UnsupportedOperationException(“Not supported yet.”);

}



//server code

//this from implements ConnectionListener, MessageListener

public void clientConnected(Client client) {



}



public void clientDisconnected(Client client) {



}



public void messageReceived(Message msg) {

System.out.print(“incoming message”);

}



public void messageSent(Message msg) {



}



public void objectReceived(Object o) {



}



public void objectSent(Object o) {



}



}







Error:



started network18-Sep-2010 12:47:22 PM me.codeninja.spidermonkey.connection.TCPConnection accept

INFO: [Server#1][TCP] A client connected with address /127.0.0.1

18-Sep-2010 12:47:22 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[Thread-2,5,main]

java.lang.ClassCastException: me.codeninja.spidermonkey.message.ClientRegistrationMessage cannot be cast to org.jme3.share.HelloMessage

incoming message at org.jme3.server.TerrainServer.messageReceived(TerrainServer.java:105)

at me.codeninja.spidermonkey.connection.Connection.fireMessageReceived(Connection.java:280)

at me.codeninja.spidermonkey.connection.UDPConnection.read(UDPConnection.java:98)

at me.codeninja.spidermonkey.connection.Connection.run(Connection.java:92)

at me.codeninja.spidermonkey.connection.ConnectionRunnable.run(ConnectionRunnable.java:48)

at java.lang.Thread.run(Thread.java:619)

18-Sep-2010 12:48:39 PM com.jme3.input.lwjgl.LwjglMouseInput destroy

You register both to receive messages of type HelloMessage and all types of messages.

In this line: server.addMessageListener(this);

This means you’ll receive all messages, and so you cant assume its a HelloMessage

How to register it ? It given me errors.



server.addMessageListener(this,HelloMessage.class); ← error

I think

server.addIndividualMessageListener(HelloMessage.class, this);

should work.

Well I try that. But not sure how to get the send and receive working on it.