Class bzProtocol
source code
This class provides BZoo applications with message packing and
unpacking services.
Exemple:
import bzMessage
def myHandlerFct(values):
messages = values
print "I've just received message(s): ", messages
# initialisation of protocol and message list
aProtocol = bzProtocol()
message_queue = []
message_queue.append(bzMessage.SayMessage("Hello World"))
# setup a handler on reception of message
self.aProtocol(bzMessage.CLIENTS_MESSAGES_MESSAGE,myHandlerFct)
# prepare raw data to send from current list of message
data2send = aProtocol.getNextDataMessage(message_queue, 1024)
SendData (data2send)
# process incoming message
data = ReceiveData ()
if (data is not None):
aProtocol.processDataMessage(data)
|
list of list of handler function
|
HandlerTable
gives the functions to
|
|
|
MessageTable
|
Add a handler on reception of a peculiar message
- Parameters:
msgType (integer.) - the type of the message to attach the handler to
fct (function.) - the handler function.
|
getNextDataMessage(self,
msg_list,
max_size)
| source code
|
Build a packed data block
- Parameters:
msg_list (String.) - The server hostname or IP adress
max_size (Integer) - the maximum size of the data packet to produce
- Returns: byte array.
- the next packed data block to send.
|
Unpack received data into messages and call associated handler.
- Parameters:
data (byte array.) - A packed data block
|