RTMP implementation in nodejs is possible?


i'm trying to make a implementation of RTMP in Node.js but after seeing the documentation and trying, i'm unable to, and i suspect this is not possible to make it seeing how node.js handle the streams of data.

i'm forking this code: https://github.com/timwhitlock/node-amf/tree/master/node-rtmp

according to the code and the poorly written adobe documentation, after the connection, the handshaking process starts, the clients send a stream of 1537 octets, where the first one is the rtmp version (should be always 3), the following 4 are the timestamp and the other 4 should be 0 (0000), all the rest of the data are random characters.

now, the linked library do all this, but get broken at the point of checking the 4 zero's. it uses the Net module to create a server, and listen on connection event. using the socket object provided by the event, set the encoding to "binary" (this type of encoding doesn't exist as far i see in the documentation http://nodejs.org/api/stream.html#stream_stream_setencoding_encoding ) and then try to check for the four zero's

i suspect that the socket is encoding in 'utf8' anyways, and there is where the stream get screw up, as printing the first bytes, is never the same data. changing to hex the encoding of the socket, i found matches that would indicate the four zero's i'm looking for:



even i could make it work like that, when i need to stream real data, as video, audio, etc.. , to the server (i know that i can write from the socket binary data passing a Buffer object and using this: https://github.com/substack/node-binary ) and the socket can't handle binary data, i will have corrupted data right?

i'm not an expert, but i tried to investigate this as far i can, even if this can't be solved, i'd like someone could tell me if i'm right or just i'm screwing up :)

Problem courtesy of: shadow_of__soul


well, my answer was on the same documentation, if i don't call at all setEncoding() on the socket object returned by the Net module, i can receive a plain binary Buffer, that i can parse at will, so this seems to be possible.

still, the data received are not 0's (on bytes 5,6,7 and 8 there is 128 0 7 2) so i need to know how to correctly parse binary data, but at least for now, this seems to be possible.

Regards, Shadow.

Solution courtesy of: shadow_of__soul


This is not an encoding issue (you are not screwing it up). The closest explanation I could find is in Red5's source:


Somehow that field is used to transmit the version of the implementation.

Discussion courtesy of: vbence

This recipe can be found in it's original form on Stack Over Flow.