Functionality comes from modules or including additional Javascript files.
Modules I've written for it are also in the portfolio to browse through:
helloworld.js:
Serve.print("Hello, world!");
echoserver.js:
/* Modules load into a context variable. */
var WSS = Serve.module("Websocket");
/* "Any" is special and means :: and 0.0.0.0 */
var wss = WSS.listen("Any", 9096);
/* In this example, simply accept incoming websocket connections and echo
* back anything received.
*/
wss.newConnection.connect( function() {
var ws = wss.accept();
Serve.print("New connection.");
ws.received.connect( function(packet) {
Serve.print("New packet: "+packet);
try {
ws.transmit("You said: "+packet);
} catch(e) {
Serve.print("Error handling packet: "+e);
}
} );
} );