How to get the number of connected users?

215 views
Skip to first unread message

webdev.andrei

unread,
Jan 9, 2011, 9:25:00 AM1/9/11
to C++ RTMP Server
Hello Andrei!

Nice work with C++ RTMP Server. I have a couple of questions for you:

1) I would like to know if there is a way to retrieve the number of
connected users to a stream. Is there a function for that? Or do you
have any idea how to achieve that?
2) Can the server do dynamic streaming (I'm referring to dynamic
streaming where the server switches to a higher/lower quality stream -
without changing the source in client player)?

Thank you very much,
Andrei.

C++ RTMP Server

unread,
Jan 9, 2011, 5:38:10 PM1/9/11
to c-rtmp...@googlegroups.com

On Jan 9, 2011, at 4:25 PM, webdev.andrei wrote:

> Hello Andrei!
>
> Nice work with C++ RTMP Server. I have a couple of questions for you:
>
> 1) I would like to know if there is a way to retrieve the number of
> connected users to a stream. Is there a function for that? Or do you
> have any idea how to achieve that?

The API is there. You can get stats about protocols/streams using BaseProtocol::GetStackStats and BaseStream::GetStats. But there is no ready-for use app for doing that. However, is relatively simple to do so

> 2) Can the server do dynamic streaming (I'm referring to dynamic
> streaming where the server switches to a higher/lower quality stream -
> without changing the source in client player)?

Again, not out of the box. However, I have few commercial applications doing just that. One example is an application pulling in a apple stream (multiple bandwidth stream) and serve it via RTMP or RTSP

Cheers,
Andrei

>
> Thank you very much,
> Andrei.
>

> You received this message because you are subscribed to "C++ RTMP Server" mailing list.
> To post to this group, send email to c-rtmp...@googlegroups.com
> To unsubscribe from this group, send email to
> c-rtmp-serve...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/c-rtmp-server?hl=en

------
Eugen-Andrei Gavriloaie
Web: http://www.rtmpd.com

webdev.andrei

unread,
Jan 10, 2011, 12:47:38 PM1/10/11
to C++ RTMP Server
Hello Andrei,
Tried to put in action what you suggested by using php-rtmp-client to
connect to the rtmp server. The code I used is this:

require "RtmpClient.class.php";
require "debug.php";
$client = new RtmpClient();
$client->connect("192.168.1.201","brvlive");
$result = $client->call("BaseProtocol::GetStackStatus");
var_dump($result);

I get this error:

Fatal error: Uncaught exception 'Exception' with message 'Packet
version 0 not supported' in /var/www-dev/rtmp-php/RtmpClient.class.php:
405
Stack trace:
#0 /var/www-dev/rtmp-php/RtmpClient.class.php(59): RTMPClient-
>handshake()
#1 /var/www-dev/rtmp-php/main.php(6): RTMPClient->connect('localhost',
'flvplayback')
#2 {main}
thrown in /var/www-dev/rtmp-php/RtmpClient.class.php on line 405

I know PHP pretty good but don't know where is the problem. It seems
that there is something wrong with the handshake process. Can you give
me some hints on this? What's the process for a correct handshake?

Thank you,
Andrei Ionescu
>  smime.p7s
> 5KViewDownload

Kirik

unread,
Jan 12, 2011, 3:13:51 PM1/12/11
to C++ RTMP Server
> Tried to put in action what you suggested by using php-rtmp-client to
> connect to the rtmp server. The code I used is this:
>
> require "RtmpClient.class.php";
> require "debug.php";
> $client = new RtmpClient();
> $client->connect("192.168.1.201","brvlive");
> $result = $client->call("BaseProtocol::GetStackStatus");
> var_dump($result);

Hi there!
You can't just call BaseProtocol::GetStackStatus via RTMP call,
because RTMPD server does not handle this action by default.
You have to define action for this call in your RTMPD application. To
do this you can overwrite RTMPAppProtocolHandler::ProcessInvokeGeneric
method in your application's rtmpappprotocolhandler.cpp file.

Take care!
KiriK

Bheam

unread,
Jan 14, 2011, 3:08:14 AM1/14/11
to C++ RTMP Server
I took a look at php-rtmp-client, and I have to say, it looks like a
rather lousy attempt at implementing RTMP. The handshake is lacking,
which won't even allow it to connect to c++ rtmp server. If you zero
out the version number in the handshake, so c++ rtmp server doesn't do
any validation, you get further, but I still failed to make a rpc call
(client just hangs).

How they (claim to) manage to connect to red5 is a mystery to me - it
must be more fault tolerant?

Michael

C++ RTMP Server

unread,
Jan 14, 2011, 9:55:36 AM1/14/11
to c-rtmp...@googlegroups.com

On Jan 14, 2011, at 10:08 AM, Bheam wrote:

> I took a look at php-rtmp-client, and I have to say, it looks like a
> rather lousy attempt at implementing RTMP. The handshake is lacking,
> which won't even allow it to connect to c++ rtmp server.

You are right on this one. However, is not the project's fault. Is the Adobe who is hurting (rather than helping) the open-source community by releasing that "dust-in-the-eye" kind of rtmp specs. That doc is the work of a sunday-drunk Adobe employe in a rainy monday morning with a 6 foot tall boss shouting at him. Unfortunately is affecting more and more projects. That's sad! In Adobe's shoes, I would be extremely embarrassed!

> If you zero
> out the version number in the handshake, so c++ rtmp server doesn't do
> any validation, you get further,

You can deactivate the handshake validation completely via config file. Just put validateHandshake=false in appselector section or directly in your target app section of you don't use appselector

> but I still failed to make a rpc call
> (client just hangs).

It hangs because is expecting a result from the server. I saw that as well. Just returning true from the server won't do the trick. You have to actually send the response back to the client even if it is void so it will know that the server completed operation. Is quite natural. See my post here:

http://code.google.com/p/php-rtmp-client/issues/detail?id=5#c9

>
> How they (claim to) manage to connect to red5 is a mystery to me - it
> must be more fault tolerant?

That I have no clue. Never tested it.

Bottom line,
IMHO is a good library that just needs some patching here and there. I would use in production after patching it. It does a good job. However, patching it is not a walk in the park and requires average-advanced knowledge about RTMP. Which is exactly why is looking unusable at the first glance

Cheers,
Andrei

>
> Michael
>
> On Jan 12, 9:13 pm, Kirik <kirill.kuznets...@gmail.com> wrote:
>>> Tried to put in action what you suggested by using php-rtmp-client to
>>> connect to the rtmp server. The code I used is this:
>>
>>> require "RtmpClient.class.php";
>>> require "debug.php";
>>> $client = new RtmpClient();
>>> $client->connect("192.168.1.201","brvlive");
>>> $result = $client->call("BaseProtocol::GetStackStatus");
>>> var_dump($result);
>>
>> Hi there!
>> You can't just call BaseProtocol::GetStackStatus via RTMP call,
>> because RTMPD server does not handle this action by default.
>> You have to define action for this call in your RTMPD application. To
>> do this you can overwrite RTMPAppProtocolHandler::ProcessInvokeGeneric
>> method in your application's rtmpappprotocolhandler.cpp file.
>>
>> Take care!
>> KiriK
>

webdev.andrei

unread,
Jan 14, 2011, 11:28:16 AM1/14/11
to C++ RTMP Server
Hello to you all!

The specification for RTMP protocol can be read here (http://
www.adobe.com/content/dam/Adobe/en/devnet/rtmp/pdf/rtmp_specification_1.0.pdf)
or downloaded from http://www.adobe.com/devnet/rtmp.html
In my opinion is not Adobe's fault as the RTMP protocol is opened and
the documentation is ok. The document has about 70 pages which is
quite a lot.

Now I'm trying to compile a new application based on flvplayback
application and to expose get the status of the base prorocol.

The code that adds the CountCurrentConnections function looks like
this:

bool RTMPAllProtocolHandler::CountCurrentConnections(BaseRTMPProtocol
* pFrom, Variant &info) {
Variant response;
BaseProtocol::GetStackStatus(info);
response = GenericMessageFactory::GetInvokeResult(request, info);
return SendRTMPMessage(pForm, response);
}

But I cannot compile and the error is saying the info is not defined
in the same namespace. I guess I don't know how to get the info from
the GetStackStatus function.

To retrieve it on the client side I will use a Flash/Flex application
that makes use of NetConnection.

I need some help to return that info back towards the client.

Thank you very much for the help with code and ideas.

Andrei.
>  smime.p7s
> 5KViewDownload

C++ RTMP Server

unread,
Jan 14, 2011, 1:57:06 PM1/14/11
to c-rtmp...@googlegroups.com
Hi,

Please study carefully the attached patch. It contains all necessary stuff for doing what you want. Also contains detailed explanations.

simple.patch

Josh Allmann

unread,
Jan 15, 2011, 5:26:05 AM1/15/11
to c-rtmp...@googlegroups.com
On 14 January 2011 08:28, webdev.andrei <webdev...@gmail.com> wrote:
> On Jan 14, 4:55 pm, C++ RTMP Server <crtmpser...@gmail.com> wrote:
>>
>> You are right on this one. However, is not the project's fault. Is the Adobe who is hurting (rather than helping) the open-source community by releasing that "dust-in-the-eye" kind of rtmp specs. That doc is the work of a sunday-drunk Adobe employe in a rainy monday morning with a 6 foot tall boss shouting at him. Unfortunately is affecting more and more projects. That's sad! In Adobe's shoes, I would be extremely embarrassed!
>
> The specification for RTMP protocol can be read here (http://
> www.adobe.com/content/dam/Adobe/en/devnet/rtmp/pdf/rtmp_specification_1.0.pdf)
> or downloaded from http://www.adobe.com/devnet/rtmp.html
> In my opinion is not Adobe's fault as the RTMP protocol is opened and
> the documentation is ok. The document has about 70 pages which is
> quite a lot.
>

Try to actually write an implementation from that spec and you won't
get very far. Completeness needs maybe 100-200 more pages, plus many
more for the variations (RTMPT, RTMPS, RTMPE, etc). I agree with
Andrei that its quality (or lack thereof) is hurting the community.

I have found Andrei's implementation does an extremely good job in
mimicking the behavior from both FMS and the Flash player. I would use
his source code as a canonical reference. Red5's is pretty good too.

Josh

webdev.andrei

unread,
Jan 17, 2011, 11:29:16 AM1/17/11
to C++ RTMP Server
Andrei,

Thank you very much for your help. Wonderful. I applied the patch and
played a little bit with it. It sends me lot of info which is good but
this also needs some clarifications. So I have some questions...
1) Will this patch get into the mainline? I'm asking because I intend
to keep the server up to date so when I'll checkout the code I would
like to have this patch also.
2) Can you explain a bit what is in the second child of the stack for
a info item; because it has a lot of info? I guess the most important
is the streams property?
3) Among all those info items I've noticed a node that in the streams
property contains a outStreamsUniqueIds property which contains the
ids of other streams. Is it correct to count the number items in
outStreamsUniqueIds to get the number of users connected? What are the
types INR and ONR4R standing for?
4) outStreamsUniqueIds & inStreamsUniqueIds tells us who with who is
connected. Is this correct?
5) The last info item is also a bit different. Is it Ok to ignore it?
What is it for?

Once again I want to thank you for your wonderful help and for your
fast reply to requests. Hope these questions are not putting to much
on you.

Andrei Ionescu.
http://www.flexer.info



On Jan 14, 8:57 pm, C++ RTMP Server <crtmpser...@gmail.com> wrote:
> Hi,
>
> Please study carefully the attached patch. It contains all necessary stuff for doing what you want. Also contains detailed explanations.
>
>  simple.patch
> 4KViewDownload
>
>
>
> Cheers,
> Andrei
>
> On Jan 14, 2011, at 6:28 PM, webdev.andrei wrote:
>
>
>
> > Hello to you all!
>
> > The specification for RTMP protocol can be read here (http://
> >www.adobe.com/content/dam/Adobe/en/devnet/rtmp/pdf/rtmp_specification...)
> > or downloaded fromhttp://www.adobe.com/devnet/rtmp.html

simonb

unread,
Jan 28, 2011, 9:35:38 AM1/28/11
to C++ RTMP Server
Can you please post the php code you are using?

Right now I have applied the patch and I get the same error you
reported before the patch.

Thanks,
Simon

On Jan 17, 4:29 pm, "webdev.andrei" <webdev.and...@gmail.com> wrote:
> Andrei,
>
> Thank you very much for your help. Wonderful. I applied the patch and
> played a little bit with it. It sends me lot of info which is good but
> this also needs some clarifications. So I have some questions...
> 1) Will this patch get into the mainline? I'm asking because I intend
> to keep the server up to date so when I'll checkout the code I would
> like to have this patch also.
> 2) Can you explain a bit what is in the second child of the stack for
> a info item; because it has a lot of info? I guess the most important
> is the streams property?
> 3) Among all those info items I've noticed a node that in the streams
> property contains a outStreamsUniqueIds property which contains the
> ids of other streams. Is it correct to count the number items in
> outStreamsUniqueIds to get the number of users connected? What are the
> types INR and ONR4R standing for?
> 4) outStreamsUniqueIds & inStreamsUniqueIds tells us who with who is
> connected. Is this correct?
> 5) The last info item is also a bit different. Is it Ok to ignore it?
> What is it for?
>
> Once again I want to thank you for your wonderful help and for your
> fast reply to requests. Hope these questions are not putting to much
> on you.
>
> Andrei Ionescu.http://www.flexer.info
> > >>> I took a look atphp-rtmp-client, and I have to say, it looks like a
> > >>> rather lousy attempt at implementing RTMP. The handshake is lacking,
> > >>> which won't even allow it to connect to c++ rtmp server.
>
> > >> You are right on this one. However, is not the project's fault. Is the Adobe who is hurting (rather than helping) the open-source community by releasing that "dust-in-the-eye" kind of rtmp specs. That doc is the work of a sunday-drunk Adobe employe in a rainy monday morning with a 6 foot tall boss shouting at him. Unfortunately is affecting more and more projects. That's sad! In Adobe's shoes, I would be extremely embarrassed!
>
> > >>> If you zero
> > >>> out the version number in the handshake, so c++ rtmp server doesn't do
> > >>> any validation, you get further,
>
> > >> You can deactivate the handshake validation completely via config file. Just put validateHandshake=false in appselector section or directly in your target app section of you don't use appselector
>
> > >>> but I still failed to make a rpc call
> > >>> (client just hangs).
>
> > >> It hangs because is expecting a result from the server. I saw that as well. Just returning true from the server won't do the trick. You have to actually send the response back to the client even if it is void so it will know that the server completed operation. Is quite natural. See my post here:
>
> > >>http://code.google.com/p/php-rtmp-client/issues/detail?id=5#c9
>
> > >>> How they (claim to) manage to connect to red5 is a mystery to me - it
> > >>> must be more fault tolerant?
>
> > >> That I have no clue. Never tested it.
>
> > >> Bottom line,
> > >> IMHO is a good library that just needs some patching here and there. I would use in production after patching it. It does a good job. However, patching it is not a walk in the park and requires average-advanced knowledge about RTMP. Which is exactly why is looking unusable at the first glance
>
> > >> Cheers,
> > >> Andrei
>
> > >>> Michael
>
> > >>> On Jan 12, 9:13 pm, Kirik <kirill.kuznets...@gmail.com> wrote:
> > >>>>> Tried to put in action what you suggested by usingphp-rtmp-client to

C++ RTMP Server

unread,
Jan 28, 2011, 10:06:23 AM1/28/11
to c-rtmp...@googlegroups.com

On Jan 28, 2011, at 4:35 PM, simonb wrote:

> Can you please post the php code you are using?
>
> Right now I have applied the patch and I get the same error you
> reported before the patch.
>
> Thanks,
> Simon
>
> On Jan 17, 4:29 pm, "webdev.andrei" <webdev.and...@gmail.com> wrote:
>> Andrei,
>>
>> Thank you very much for your help. Wonderful. I applied the patch and
>> played a little bit with it. It sends me lot of info which is good but
>> this also needs some clarifications. So I have some questions...
>> 1) Will this patch get into the mainline? I'm asking because I intend
>> to keep the server up to date so when I'll checkout the code I would
>> like to have this patch also.

Unfortunately no. This is not going to be pushed into the main line because is too specific. The information provided is quite complete (extreme actually). That was just an example of a complete output that the server can produce. You have to make it more light. For example, instead of getting the whole list of connections, is just better o get the count of them directly, assuming that the count is what you are interested in. Same goes for the streams: Instead of getting info about the carrier connection, you should get the info about the streams if that is what interests you. Bottom line, get what you want, not all of it


>> 2) Can you explain a bit what is in the second child of the stack for
>> a info item; because it has a lot of info? I guess the most important
>> is the streams property?

Each element in the stack is a protocol from that particular stack. All of them have a fixed structure. On top of that fixed structure there is a variable structure, depending on the type of the protocol. What you see is probably the detailed info about a RTMP protocol


>> 3) Among all those info items I've noticed a node that in the streams
>> property contains a outStreamsUniqueIds property which contains the
>> ids of other streams. Is it correct to count the number items in
>> outStreamsUniqueIds to get the number of users connected?

Yes, that is correct. that is the number of consumers for that particular stream. Needless to say, if you only want that, is a total waste of resources to get this whole info just to extract that. You should design a special call for that for extracting that info and only that info.


>> What are the
>> types INR and ONR4R standing for?

For streams types, the convention is at follows:
1. First letter designates the direction:
I - inbound (data is published into the server)
O - outbound (data is going away from the server. Player doing playback)
N - neutral (the stream is not yet inbound or outbound. The resources were allocated for it, but is not yet decided what it will be used for)
2. Second letter is the kind of the stream:
F - file
N - network
3. Rest of the letters are arbitrary and used to further describe the protocol. It has some logic in it, but you should not relay on them having a special meaning
Example:
INR - Inbound Network RTMP (someone publish a stream)
ONR4R - Outbound Network RTMP for an inbound RTMP stream
ONR4TS - Outbound Network RTMP for an inbound TS Stream
NR - neutral RTMP stream


>> 4) outStreamsUniqueIds & inStreamsUniqueIds tells us who with who is
>> connected. Is this correct?

Yes

>> 5) The last info item is also a bit different. Is it Ok to ignore it?
>> What is it for?

Don't remember the output. Can you paste it on pastebin.com?

>>
>> Once again I want to thank you for your wonderful help and for your
>> fast reply to requests. Hope these questions are not putting to much
>> on you.

You are welcome


>>
>> Andrei Ionescu.http://www.flexer.info
>>
>> On Jan 14, 8:57 pm, C++ RTMP Server <crtmpser...@gmail.com> wrote:
>>

Cheers,
Andrei

simonb

unread,
Jan 28, 2011, 11:03:49 AM1/28/11
to C++ RTMP Server
OK, I can answer my own question now.

1) In rtmpserver.lua set "validateHandshake=false".

2) This is the php code to access GetAllActiveConnections...
<html>
<body>
<pre>
<?php
require "RtmpClient.class.php";
require "debug.php";
$client = new RtmpClient();
$client->connect("localhost","flvplayback");
$result = $client->call("getAllActiveConnections");
var_dump($result);
?>
</pre>
</body>
</html>

Anis Khwaja

unread,
Feb 26, 2011, 3:04:07 PM2/26/11
to C++ RTMP Server

> Unfortunately no. This is not going to be pushed into the main line because is too specific. The information provided is quite complete (extreme actually). That was just an example of a complete output that the server can produce. You have to make it more light. For example, instead of getting the whole list of connections, is just better o get the count of them directly, assuming that the count is what you are interested in. Same goes for the streams: Instead of getting info about the carrier connection, you should get the info about the streams if that is what interests you. Bottom line, get what you want, not all of it

unfortunately I am completely unfamiliar with how to do this, I
applied the patch and am getting lots of info, can you show how to get
just the connection count?

thanks

Anis Nielsen

unread,
Feb 26, 2011, 3:15:14 PM2/26/11
to c-rtmp...@googlegroups.com
Hi !

is this all is needed to get the total number of outgoing connections
, using php?
Is there any php library to be used beside ?

Cheers
Anis Nielsen

> You received this message because you are subscribed to "C++ RTMP Server"
> mailing list.
> To post to this group, send email to c-rtmp...@googlegroups.com
> To unsubscribe from this group, send email to
> c-rtmp-serve...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/c-rtmp-server?hl=en
>

--
Sent from my mobile device

webdev.andrei

unread,
Feb 26, 2011, 5:58:40 PM2/26/11
to C++ RTMP Server
I did manage to get only the connection count. I'll be back with the
code I implemented to get only the connection count.

Andrei Ionescu.

Anis Nielsen

unread,
Feb 26, 2011, 7:52:51 PM2/26/11
to c-rtmp...@googlegroups.com
Thank you Andrei for willing to share this

i was thinking about how to setup some loadbalancing  using php .. i was stuck with how to get the number of connected users to one app on one live stream name ; If you managed that, should be easy implementing this , cool! :)

Cheers
Anis Nielsen


Madhawa Jayanath

unread,
Feb 26, 2011, 9:15:10 PM2/26/11
to c-rtmp...@googlegroups.com, webdev.andrei
Hello Andrei,
You may publish those info on the Wiki too :)

Cheers

You received this message because you are subscribed to "C++ RTMP Server" mailing list.
To post to this group, send email to c-rtmp...@googlegroups.com
To unsubscribe from this group, send email to
c-rtmp-serve...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/c-rtmp-server?hl=en



--
Best regards,
Madhawa Jayanath

Senior Software Engineer
101 Global Co.,Ltd.
999/9 # 2409 Rama 1, Pathumwan
Bangkok, 10330. Thailand
INUM +883-510-07-403-6540
Tel. +66.840839412
FAX. +66.26480995


Sent from my NoteBook® by Hand

WEBDEV.andrei

unread,
Feb 28, 2011, 3:54:26 AM2/28/11
to c-rtmp...@googlegroups.com
Here is a patch for the getNoOfConnectedUsers functionality.
The patch is made over the 359 svn version of C++ RTMP Server.
Place the patch in the root of your working copy and patch it using: patch -p0 -i getNoOfConnectedUsers.diff
It should display that 3 files were successfully patched.

Andrei Ionescu
getNoOfConnectedUsers-vs-359.diff
Reply all
Reply to author
Forward
0 new messages