开发者

How can I send messages from Red5 to my Flash AS3 App?

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜