Skip to content
1egoman edited this page Jun 21, 2014 · 2 revisions

Listeners

Normally, communication in Quail goes from client to server, only. Listeners allow the server to do the reverse, and send messages back to the client. In Quail, all packets that are being sent out are appended to the end of a list. If a packet is appended to the stack, it will be sent the next time any client connects. A normal query will return the stack, and empty it. If, for example, you wanted only the last packet on the stack (the one you requested with the query), you could specify the n GET variable with a value of 1. A value of zero is the default and means to send the whole stack.

Setting up a Listener

  1. In the plugin's info.json, add
"listener": "example.py:exampleListener"

in the same format as the main parameter. Then, create the listener method

def exampleListener(parent):
  """ example listener """
  pass

Sending messages with a Listener

def exampleListener(parent):
  """ example listener """

  # send packet to client
  msg = {"status": STATUS_OK, "type": TYPE_PUSH, "text": "test response"}
  parent.stack.append(msg)

For any message that is to be sent to the client, the type should be TYPE_PUSH. Almost always, the status should also be STATUS_OK. It is very bad practice to send lots of packets in a short amount of time.

Clone this wiki locally