Flex RTMP client - apache-flex

I'm trying to write an rtmp client with flex. The problem is that I have no idea where to start. Could someone please answer how I would go about doing this, or point me to a site that does? Thanks. I don't even know what classes to use and such.

See Wiki Real Time Messaging Protocol as a starting point
and there are few sample clients
JUV RTMP Client
php-rtmp-client
hopes that works

You don't have to write your own RTMP client because Flash already implements a RTMP client called NetConnection.
To create a basic connection you could do the following:
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect('rtmp://127.0.0.1/application');
function onNetStatus(e:NetStatusEvent):void
{
switch (e.info.code)
{
case 'NetConnection.Connect.Success':
// Connection with the RTMP server has been established
break;
case '...':
...
}
}
The code 'NetConnection.Connect.Success' you see is one of the codes the server returns, have a look over here for an overview of all the codes.
You should probably read up on the documentation first and then come back with a more precise question.

Related

How to communicate between a libwebsockets client and a websocket server like Nginx?

I try to implement a websocket client (with libwebsockets in C and it's not an option). As example, i used the test-client.c given with the library.
My websocket-client actualy works fine with the test-server.c . But i experienced some complications to communicate with an nginx server.
As i understand, the handshack doesn't end up well because nginx doesn't know my websocket client's sub-protocol.
Well, it appears, like in test-client.c i'm implementing my own sub-protocol (with its own name, its own callback function).
My questions are :
Is there a way to not use a specific websocket sub-protocol with libwebsockets ?
If not, am i supposed to implement an existing one (client side) like WAMP or something in this list? (I do not want to reinvent the wheel...)
If not, does it exist a "default" websocket subprotocol that i can specify to nginx and in which it could be compatible with my websocket-client ? (I'm only doing some simple send/receive action with my client. Implementing a libwebsockets client seems completly useless if it can only communicate with a libwebsockets server)
Are my questions relevant? If not why ? What am i missing ?
Any help is appreciated.
Thanks!
As discussed with Andy, the libwebsockets designer (https://github.com/warmcat/libwebsockets/issues/834), the simpliest way to make it works is to not named the sub-protocol in the structure defining the websocket sub-protocol client's side :
/* list of supported sub-protocols and callbacks */
static struct lws_protocols ws_protocols[] = {
{ NULL, ws_callback, 0, 128, },
{ NULL, NULL, 0, 0 } /* end */
};
Libwebsockets client doesn't try to negociate with sec-websocket-protocol in the header, the handshake works just fine with nginx.

How to identify the protocol of the Meteor connection

I've wondered how to identify the current protocol if it's using websocket or polling.
-- in the client. (appended for certainty)
I've found a valid information from the debug console.
Meteor.connection._stream.socket.protocol
and it seems to have one value among...
['websocket',
'xdr-streaming',
'xhr-streaming',
'iframe-eventsource',
'iframe-htmlfile',
'xdr-polling',
'xhr-polling',
'iframe-xhr-polling',
'jsonp-polling'];
is there more grace way to identify the current protocol?
and when would it be the fastest timing to detect the protocol?
By the way, I need it to use a different DDP server when the sticky sessions needed since AWS ELB doesn't support sticky sessions and websocket at the same time.
Meteor uses DDP protocol. To connect to a different Meteor server and call its methods, use DDP.connect as follows.
import { DDP } from 'meteor/ddp-client'
DDP.connect(url)
Unfortunately, there is no graceful to get the protocol. onConnection returns an object which has some info.
Meteor.onConnection(obj =>
{ console.log(obj.httpHeaders.x-forwarded-proto); });
This returns 'ws' for websocket. This way of getting the protocol is not graceful!
Meteor.status() gives a reactive data source.
(https://docs.meteor.com/api/connections.html#DDP-connect)
if (Meteor.isClient) {
Tracker.autorun(() => {
const stat = Meteor.status();
if (stat.status === 'connected') {
console.log(Meteor.connection._stream.socket.protocol);
}
});
}
something like that will give the current protocol in the client side.

How does a VLC client ask the server for more data in application layer (HTTP)?

I am working on a project related to video streaming. I have been reading the http code extensively in the access_output and access modules. My question is regarding how the client asks the server to send more data in the application layer, specifically using http. I assume it is within the httpd file located in the src/network folder, but I have been writing to log files and I can't seem to figure out how the client asks for the data. It really seems like the server just sends it to the client without acknowledgement, but I highly doubt this is the case.
Thank you so much for your help!
Requesting more data is achieved using HTTP GET with a Range header.
Examples:
Range: bytes=123-
Range: bytes=123-456
In VLC you can find the relevant code in modules/access/http.c:
static int Request( access_t *p_access, uint64_t i_tell )
{
[...]
/* Offset */
if( p_sys->i_version == 1 && ! p_sys->b_continuous )
{
p_sys->b_persist = true;
net_Printf( p_access, p_sys->fd, pvs,
"Range: bytes=%"PRIu64"-\r\n", i_tell );
net_Printf( p_access, p_sys->fd, pvs, "Connection: close\r\n" );
}
See also: HTTP Range Requests in the RFC.

Meteor Server Websockets

I am looking to create a websocket on Meteor Server (not client) to connect to an external site. I know the URL I am going to be hitting as well as what data to expect, but I am unclear as to how exactly to create the websocket itself. All the searching I do presents me with solutions for the client, but I have yet to run into anything that serves as a server solution.
Is there anything out there I missed that fills this purpose? Atmosherejs.com doesn't list anything, and searching around on google/github didn't reveal anything either. Is there something built into Meteor that already accomplishes this?
The following code is for opening a Socket in Meteor on Port 3003. It convert the data from the socket (sendet from client) to a JSON-Object. So this means, the following code is a socket, which receive JSON.
Fiber = Npm.require('fibers')
// server
Npm.require('net').createServer(function (socket) {
console.log("connected");
socket.on('data', function (data) {
socket.write("hello!");
var o = JSON.parse(data.toString());
console.log(o);
Fiber(function() {
console.log('Meteor code is executing');
//=> Meteor code
}).run();
//console.log(data.toString());
//socket.close();
});
})
.listen(3003);

How to get the current server IP of request when multiple interfaces are used?

Sorry, but I was not able to find the answer for this simple question after two attempts of googaling:
How can I get the current IP of the server connection a client is handled on? Is it possible to extract this somehow Meteor.status()?
(Background: we have different IPs which are served by the same instance. But we like to distinguish by the IP entry point.)
Meteor.status() don't have the information. But you can publish the IP address to the client or make a method that return it.
This is a pseudo-code and I don't know if this works. It's just an idea:
server.js:
var THIS_IP = '8.8.8.8'; // Try to get it dinamically with node or some npm package
Meteor.methods({
'serverIp': function () {
return THIS_IP;
}
});
client.js:
Meteor.call('serverIp', function (err, serverIp) { //do something with the IP });
EDIT: Sorry about this response. Just saw you have 2 IPs in same server. Maybe this hack can solve problems for now?
how to get external ip of the server from node.js

Resources