Main View

This is the main view module which manages main tornado connections. This module provides request handlers for managing simple HTTP requests as well as Websocket requests.

Although the websocket requests are actually sockJs requests which follows the sockjs protcol, thus it provide interface to sockjs connection handlers behind the scene.

IndexHandler

class mosquittoChat.apps.main.views.IndexHandler(application, request, **kwargs)

This handler is a basic regular HTTP handler to serve the chatroom page.

get()

This method is called when a client does a simple GET request, all other HTTP requests like POST, PUT, DELETE, etc are ignored.

Returns:Returns the rendered main requested page, in this case its the chat page, index.html
__module__ = 'mosquittoChat.apps.main.views'

ChatWebsocketHandler

class mosquittoChat.apps.main.views.ChatWebsocketHandler(session)

Websocket Handler implementing the sockjs Connection Class which will handle the websocket/sockjs connections.

on_open(info)

This method is called when a websocket/sockjs connection is opened for the first time.

Parameters:
  • self – The object
  • info – The information
Returns:

It returns the websocket object

on_message(message)

This method is called when a message is received via the websocket/sockjs connection created initially.

Parameters:
  • self – The object
  • message (json string) – The message received via the connection.
on_close()

This method is called when a websocket/sockjs connection is closed.

Parameters:self – The object
Returns:Doesn’t return anything, except a confirmation of closed connection back to web app.
__module__ = 'mosquittoChat.apps.main.views'