

= SpiderMonkey (Deprecated!)

+++<abbr title="Application Programming Interface">API</abbr>+++<<jme3/advanced/networking#,networking>><<spidermonkey/migration#,migration>>
SpiderMonkey is a high performance Java networking engine, aiming to provide game developers a stable and efficient networking system. It's also perfectly capable of doing anything other than game networking. SpiderMonkey is part of jME3 and can be found in the src/networking directory.
*Author:* Lars 'Levia' Wesselius+

*License:* link:http://www.opensource.org/licenses/bsd-license.php[New BSD license]+

*Blog:* link:http://codeninja.me/tag/spidermonkey/[http://codeninja.me/tag/spidermonkey/]+

*Forum:* link:http://jmonkeyengine.org/groups/spidermonkey/forum/[http://jmonkeyengine.org/groups/spidermonkey/forum/]+

A tutorial trail can be found below, and below that all different aspects of SpiderMonkey are explained. These tutorials are to be updated upon SVN HEAD, so if new features are added in SVN, you should tutorials arriving of them soon.



=== Tutorial trail

.  <<spidermonkey/tutorial/connection#,Connections>>
.  <<spidermonkey/tutorial/sending_and_receiving_messages#,Sending and receiving messages>>
.  <<spidermonkey/tutorial/serializing#,Serialization>>
.  <<spidermonkey/tutorial/compression#,Compression>>
.  <<spidermonkey/tutorial/services#,Services>>
.  <<spidermonkey/tutorial/streaming#,Streaming>>


== Explanation of SpiderMonkey's inner workings


=== Connection protocols

SpiderMonkey supports both TCP and UDP, and is also extendable to provide others. Possible future protocols may be RUDP, UDP Lite, and SCTP. SCTP will be added in Java 7, and will therefore probably added to SpiderMonkey after it's released. Please note that the language level of SpiderMonkey is 1.5, so it will definitely not be part of the standard +++<abbr title="Application Programming Interface">API</abbr>+++ for a few years.



=== Clients

SpiderMonkey creates two connections by default. A TCP connection for a reliable connection, and an UDP 'connection' footnote:[UDP is connectionless] for fast message handling. A problem arises here: these two connections mean that even though there are two connections, there's only one client to represent both the connections. In SpiderMonkey you don't have to worry about that. The server has a client manager which deals with this problem. Upon connecting, clients have to send a ClientRegistration message to link their TCP and UDP connections together. Upon receiving those two messages, server combines the clients into one, and provides this client to you. This means you can call both TCP and UDP methods on the client. If you still want to receive the 'local' client of a connection, you can do so by calling the appropriate messages in the Server class.



=== Serializing

Serializing is an aspect that received a lot of attention. I wanted it to be simple for people to register their own messages, but also be able to register serializers for their own object types. The system works by registering classes to serializers. Generally, a serializer does not exist without a class it can serialize - simply because it doesn't have to: Why have a serializer when there's nothing to serialize. A lot of work has been put into making it as efficient as possible. What can be left out, is left out, and what can optimized, is optimized.



===== Field serializer

The default serializer requires some explanation. This serializer serializes all classes that have no (registered) serializer. The field serializer works by saving all fields internally, so it can access them on serialization faster. The fields are taken, and their types are checked. They are put through a serializer again (which serializer depends, of course, on the data type). Then they are ready to be written to the buffer. As you can tell, this is quite a simple serializer, and should be used if your message don't require extra attention. See <<spidermonkey/tutorial/serializing#,this tutorial>> if you want to know how to register your own messages or serializers.



=== Service system

The service system is in fact a tiny system. It's meant to solve a small, but annoying problem. Imagine you have SpiderMonkey as your networking library, and other people have made extra's for it. Excellent, of course, but they may all require different initialization! Perhaps you have to instantiate one yourself by using new, or maybe another works by calling a factory method; the service system exists to avoid that problem. All extras should use this system. Please see <<spidermonkey/tutorial/services#,the service tutorial>> on how to use this system.



=== Compression

By default SpiderMonkey supports compressing messages. It's been made to where you have complete freedom over what messages you wish to compress. See <<spidermonkey/tutorial/compression#,this tutorial>> on how to use these special messages.

<tags><tag target="documentation" /><tag target="network" /></tags>
