Web Socket¶
The implementation of Web Socket in Tori Framework incorporates Tornado’s Web Socket Handler with Tori’s cookie-based Session Controller, which is pretty much like working with Controller.
Here is an example.
Suppose I want to create a message-relay module
from council.common.handler import WSRPCInterface
# where WSRPCInterface inherits from tori.socket.rpc.Interface
class MathAPI(WSRPCInterface):
def add(self, a, b):
return a + b
Then, the client just has to send the message in JSON format.
{
"id": 12345
"method": "add"
"data": {
"a": 1,
"b": 2
}
}
Then, the server will reply with.
{
"id": 12345
"result": 3
}
See More¶
- Web Socket (Reference)