Building a Custom Acknowledging Channel
In this section, we’ll build a custom acknowledging channel for the RTMP protocol, even though you can implement a similar class for AMF-based messaging. The principles of creating custom channels remain the same regardless of the selected protocol. We’ll discuss the differences of the communication protocols in Chapter 6.
As stated earlier, you need to overload the receive()
method and, for each incoming instance
of ReliableServerMessage
, add the
clientId
concatenated with the
message sequence number to the array called received
:
override public function receive( msg:IMessage, ...rest:Array) : void { if (msg is ReliableServerMessage) { var seqNo : Number = Number(msg.headers["seqNo"]); received.push( msg.clientId + "|"+ seqNo); } super.receive( msg, rest); }
Every time the new message arrives from the server, the method
receive()
will be called and a new
reliable message will be added to the array received
. As a reminder, adding a seqNo
in the message header should be done in
the Java code that sends the message. You’ll see the use of the message
property clientId
a little later, on
the server’s QoSAdapter
; it’s used to avoid
collision between multiple clients, potentially confirming the same range
of message sequences.
Figure 5-5. Classes involved in the No Server Message Left Behind solution
The code of the client’s custom RTMP channel is presented ...
Get Agile Enterprise Application Development with Flex now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.