The spidermonkey tutorial

I dunno if this is the right place to write this, I basically ask if there is anyone who are interested of a updated version of the SpiderMonkey tutorial I might be able to update this (if the Author allow me to do that). I will going through this to learn more how SpiderMonkey works, but if there is no interest I will use another API instead.


Yeah, the SpiderMonkey tutorial is pretty out of date and should definitely be updated to the new API. There is a document I posted on converting an app that uses the old API to use the new one. Maybe that helps someone convert the tutorial, too.

…I’d have done it but my time has been split too many ways already lately.

It would be great if someone step up to write Spider Monkey tutorials. :slight_smile:

Maybe a completely new tutorials needs to be done. I give the old tutorial a try first and see how much of that could be used with the new revamp. I don’t have a big knowledge about network programming but if I found something interesting I could put up that as well. My project I am working at is all about network so guess I will learn a lot. I think any links to such tutorials could be placed at the top of this page If you have a better idea please tell me.

The linked document is the best place to start. (even if I do say so myself.:))

Some random thoughts as you get under way:

-Serializer and the @Serializable stuff is probably the trickiest thing you’ll have to deal with… though it’s at least a lot friendlier error-message-wise than it used to be.

-It’s a good idea to put a static utility method on a class somewhere that registers all of your messages with the Serializer and make sure to call that initialize method from both client and server.

-The TestChatClient and TestChatServer are decent examples of the basic SpiderMonkey usage… even if a little compact.

-Pay attention to the warnings that SpiderMonkey kicks out at runtime. It used to fail silently for a lot of the common mistakes but I’ve done my best to make it easier to use in this regard.

And feel free to ask questions here if you get stuck beyond what that one document provides. Seeing others bump their way through sometimes gives me ideas on how to improve things for the next person.

1 Like

Where is the TestChatClient and TestChatServer you talk about, I cannot find it.

In the JME tests under networking. Do you have the other JME tests?

I can probably dig up the link for it in the SVN web browser if you don’t have them.

There, I found it :slight_smile: I am trying to figure out how the connector filter works now, I need to do a check with the filterConnector function that takes a InetSocketAddress. I don’t know what I should use for parameter.

Okey, something like this could work:

ConnectorFilter cf = new MyConnectorFilter();

Server myServer = Network.createServer(4040, 5050);


Client myClient = Network.connectToServer(“localhost”, 4040, 5050);


System.out.print(cf.filterConnector(new InetSocketAddress(“localhost”, 4040)));

In discover host section they suggest a code that connecting to each server it found and saying that it wouldn’t work properly. I think it would be better to make it try to connect until it found a server where connection are successful. How do I tell if a connection failed?

ConnectorFilter is part of the old deprecated API. I think I have accidentally left it undeprecated but everything in the “connections” package is supposed to be deprecated.

What is it that you are trying to do with it?

Not sure, filter connections? Like banning I think.

Also, there is any new method for getting the server list? Client.discoverHosts() doesn’t exists it seems and there is no convention for that…

Seemed a bit illogical that it was the Client who checked up all servers. :stuck_out_tongue:

I want to add some kind of host discovery but haven’t ported the old approach forward. It only worked on a LAN and I’d like to somehow see about standardizing an API to link to game matching services or something.

re: filtering… I have not implemented auto-banning yet. When I do it will use the filtering that is in the network package that is currently used to filter broadcast messages.

Game matching services? You mean some kind of master server thingy with a list of servers from different games?

Wouldn’t it be cool?

Yeah, something where a game server could register itself so that other clients could find it. It’s just an idea on paper. I may prototype it for Mythruna.

Indeed it would be cool. Looking forward to this. :slight_smile:

Would this be a good way to use the Message class:


class HelloMessage implements Message {

boolean F;

String hello = "Hello!";

public Message setReliable(boolean f) {

F = f;

return this;


public boolean isReliable() {

return F;



I am not sure what the F is and why the set method should return a Message object trough.

Just extend AbstractMessage to get all of that. So:



public class HelloMessage extends AbstractMessage {

String hello = “Hello!”;


Though, obviously, most messages will have constructors, get methods, etc. most likely. Just remember that if you add your own constructors that all Messages need to also have a no-arg constructor.

For the other…

setReliable() tells SM how you’d like the message to be sent… basically TCP=reliable, UDP=fast but unreliable.

setReliable() returns Message because the old one did and I saw no reason to change it. It allows you to do things like:

[java]client.send( new MyMessage().setReliable(true) );[/java]

1 Like

Ah, clever! I haven’t really understand what should be in a message class, but that makes more sense now. Thank you!

The message class is for whatever data you need to send back and forth between the client and the server. For example, the client may send a message to the server with position information, etc. The server may broadcast out world state from all of the collected stuff.

…or as in the TestChatClient and TestChatServer (probably the most succinct examples). The Message implementation is what holds the chat message that the client sends to the server and that the server sends back out to all of the clients.

Okey I get it. In the test chat client they have a SendAction thing that as I understand you call when you want to send a message. I am not sure how the actions works, it seems to be a new thing, at least in the network.

SendAction is a Swing thing. It’s what is called when you click the send button in the GUI. So that’s the user interface code.

…what it’s doing is networking stuff. Creating the message, sending it to the server, etc.

Okey, so the send action isn’t a jMonkey thing then?

And I got error when I try

static class SrvrMsg implements MessageListener

public void messageReceived(Server source, Message m) {

What is wrong with that? It works without static...
And myServer.addMessageListener(new SrvrMsg(), HelloMessage.class); gives error as well if I don't remove the tag.