Ping example

The browser requests the ping method of the server every 2 seconds. When sending the ping request -> ping is written to the browser window and upon receiving the response a <- pong is added.

Server - examples/

#!/usr/bin/env python

import example_pythonpath
from example_utils import ExampleServer, ExampleStaticFile

class PingServer(ExampleServer):
    urls = [
        ('/', ExampleStaticFile('ping.html')),
    ] + ExampleServer.urls

    def rpc_ping(self, request):
        return 'pong'

if __name__ == '__main__':

Client - examples/ping.html

<!DOCTYPE html>


	<title>Mushroom Test Client</title>


<script type="text/javascript" src="/js/mushroom.js"></script>
<script type="text/javascript">
	var client = new mushroom.Client({
		url: '/'
	window.setInterval(function() {
		document.write('<div>&rarr; ping</div>');
		client.request('ping', null, function(data) {
			document.write('<div>&larr; pong</div>');
	}, 2000);