Question

I'm a bit confused. I would like to send messages from my Red5 Server to my Flash App... but I don't find any information how to do that...

Can anyone help me?

Was it helpful?

Solution

Hmm, by definition, the server serves and the client requests. So to create a push scenario, you still have to first initialize a connection from the client to the server. Then you can leave the connection idle until you need to send something to the client. Polling is the other method, where the server holds on to the messages and the client frequently checks in to see if new messages are available. A server cannot initiate a connection to the client. That would make the client a server. In other words, you could have the flash client register it's current IP with the server and open up a port itself, establishing itself as a server. Then the Red5 server becomes a client and can connect to the server inside the flash client. But I imagine many security restrictions will prevent your flash program from acting as a server in the real world.

OTHER TIPS

This looks like a good start: http://www.red5tutorials.net/index.php/Tutorials:Getting_Started_With_Red5_Server

See near the bottom for their simple flash client.


Edit: More options given now that it's clear we're going from server-client:

Looks like you need to do something like this: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetConnection.html

and

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html

which would mean using "NetStream.play()" to get the server to stream data to the client.

Or you might want to look at the Socket class(es) and manually create a direct socket connection between the client and server.

Keep in mind here, I've never used Red5. Just trying to help :)

For anyone who didn't find an answer until today: I am working in red5, and you can send message from red5 to flash by a RemoteSharedObject in AS3 connecting to a sharedobject in red5.

Server Code:

    ISharedObject so = getSharedObject(scope, "chat");
    so.setAttribute("message","Welcome");

Client Code:

        so = SharedObject.getRemote("chat", connection.uri, false);
    so.connect(connection);
    so.addEventListener(SyncEvent.SYNC, syncChatHandler);

    private function syncChatHandler(event:SyncEvent):void { 
    Alert.show(so.data.message,"Information");
    }

This code will show an alert on users connected with the message "Welcome". From here read a lot of documentation and use your imagination.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top