Hi there from a newcomer,

In the process of building my own Python AMF/RTMP client, I have
decoded the content (or lack thereof) of the first handshaking packets
sent in a RTMP session. These packets are mentioned at
http://www.osflash.org/rtmp/protocol#handshake and
http://www.osflash.org/rtmp/protocol#fn1

As has already been discovered, the contents of these packets do not
seem to make any difference in the operation of the RTMP session -
indeed, the version of the Red5 server I downloaded (0.6 RC1) does not
attempt to match these packets to the ones generated by Flash Media
Server, instead sending null bytes. However I thought this may put
some curious minds at ease, or perhaps bring the protocol slightly
closer to that of FMS's, even if it isn't beneficial in any great
regard :) Hopefully this is the correct place to post such a thing.


The contents (excluding the initial 0x03 channel ID byte) are:

0x000 - 0x003: current system uptime in milliseconds as a
network-ordered unsigned int

0x004 - 0x007: seemingly always 0 bytes

0x008 - 0x600, the even bytes: the values f(1) to f(764) given by the
following recurrence relation:
f(0) = system uptime in ms as in 0x000 - 0x003
f(n) = (f(n - 1) * 0xB8CD75 + 1) & 0xFF

0x008 - 0x600, the odd bytes: from what I can tell by observing the
Flash Player in a debugger (the way I decoded this pattern), these
bytes are never touched from allocation to sending over the network,
and are hence effectively undefined. I just set them to zero.


Here is a simple Python routine to generate the handshake, given an
uptime in ms:

-----
import struct

def gen_handshake(uptime_ms):
        handshake = struct.pack("!I", uptime_ms) + struct.pack("!I", 0)

        x = uptime_ms
        
        for i in range(0, (0x600 - 8) / 2):
                x = (x * 0xB8CD75 + 1) & 0xFF
                handshake += struct.pack("!H", x << 8)
        
        return handshake
-----


One can write a similar routine to check handshakes from clients
(ignoring the appropriate odd undefined bytes mentioned above) if so
desired.


I hope this is of some interest or use to someone, even if it does
nothing for the project as a whole :)

-- Matt D

_______________________________________________
Red5 mailing list
Red5@osflash.org
http://osflash.org/mailman/listinfo/red5_osflash.org

Reply via email to