我正在编写一个 Flex 应用程序。
服务器端应用程序是基于 Red5 1.0 的 Java 应用程序。该连接是通过 RTMPE 协议建立的。(结果与 RTMP 或 RTMPE 相同)。
我能够正确连接到服务器并进入和离开房间,但我无法连接到房间中的共享对象。使用非持久共享对象。
我使用以下代码在服务器端的房间中创建了一个共享对象:
private void createSharedObject (IScope scope, String soName, boolean persistent) {
ISharedObjectService service= (ISharedObjectService) ScopeUtils
.getScopeService(scope,
ISharedObjectService.class,
false);
service.createSharedObject(scope, soName, persistent);
}
private ISharedObject getSharedObject(IScope scope, String soName,boolean persistent) {
ISharedObjectService service = (ISharedObjectService) ScopeUtils
.getScopeService(scope,
ISharedObjectService.class,
false);
return service.getSharedObject(scope, soName,persistent);
}
public ISharedObject getRoomSharedObject() {
final String soName = "room_" + this._scope.getName();
log.debug("application found. creating shared object");
log.debug("shared object: {} not found for scope: {}. creating one",new Object[]{soName,this._scope.getContextPath()});
createSharedObject(this._scope, soName, XpoConstants.persistentSharedObjects);
ISharedObject so = getSharedObject(this._scope,soName, XpoConstants.persistentSharedObjects);
so.clear();
return so;
}
然后用户进入我得到连接的正确房间,并在他的最后调用一个函数并提供共享对象名称,这样他就会知道要使用以下代码连接什么:
IConnection conn = Red5.getConnectionLocal();
IServiceCapableConnection sc = (IServiceCapableConnection) conn;
sc.invoke("<function name>", new Object[]{this._so.getName(),...});
现在在客户端,我在 flex 应用程序中使用以下代码来获取远程共享对象:
var roomSharedObject:SharedObject = SharedObject.getRemote(soName, SharedUtils.getNetConnection().uri, Finals.persistentSharedObject);
roomSharedObject.addEventListener(NetStatusEvent.NET_STATUS, this._parse);
roomSharedObject.addEventListener(SyncEvent.SYNC,this._parse2);
roomSharedObject.connect(SharedUtils.getNetConnection());
...
private function _parse(e:NetStatusEvent):void {
trace("NETSTATUSEVENT");
trace("########## EVENT INFO CODE: " + e.info.code);
}
private function _parse2(e:SyncEvent):void {
trace("SYNCEVENT");
}
我从 red5 得到的唯一消息如下:
[INFO] [pool-8-thread-12] org.red5.server.so.SharedObject - Deleting shared object room_3963 because all clients disconnected and it is no longer acquired.
我猜想应该触发 NetStatusEvent 会出现某种错误消息,但我根本没有收到任何跟踪消息!我从 red5 得到的唯一信息是共享对象被删除,这意味着该客户端尝试连接一秒钟并断开连接。
我厌倦了google,厌倦了red5 google group。我迷路了!任何有关该问题的信息将不胜感激。
谢谢你!
更新
好的,我创建了一个较小的客户端和服务器..
在服务器端,appConnect 函数只返回 true。
该客户端是具有以下代码的 flex 4.6 客户端:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" creationComplete="init()"
minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private var nc:NetConnection = new NetConnection();
private function init():void {
nc.proxyType = "best";
nc.objectEncoding = ObjectEncoding.AMF0;
nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
nc.connect("rtmpe://127.0.0.1/ufktest");
}
private function checkConnect (event:NetStatusEvent):void
{
switch (event.info['code']) {
case 'NetConnection.Connect.Success':
{
_red5Connected();
trace('connected succesfully');
break;
}
case 'NetConnection.Connect.Closed':
{
_red5Disconnected();
trace('connection closed');
break;
}
case 'NetConnection.Connect.Rejected':
{
_red5Disconnected();
trace('connection rejected' );
break;
}
case 'NetConnection.Connect.Failed':
{
_red5Disconnected();
trace('connection failed');
break;
}
case 'NetConnection.Connect.AppShutDown':
{
trace('app shut down');
_red5Disconnected();
break;
}
default:
{
trace("unknown netconenction status: " + event.info['code']);
break;
}
}
}
private function _red5Connected():void {
trace("red5 connection was successful");
var roomSharedObject:SharedObject = SharedObject.getRemote("moshe",nc.uri,false);
roomSharedObject.addEventListener(NetStatusEvent.NET_STATUS, _parse);
roomSharedObject.addEventListener(SyncEvent.SYNC,_parse2);
roomSharedObject.connect(nc);
}
private function _parse(e:NetStatusEvent):void {
trace("NETSTATUSEVENT");
trace("########## EVENT INFO CODE: " + e.info.code);
}
private function _parse2(e:SyncEvent):void {
trace("SYNCEVENT");
}
private static function _red5Disconnected():void {
trace("disconnected from red5");
Alert.show("could not connect to server, please try again later");
}
]]>
</fx:Script>
当我运行客户端应用程序时,它仍然连接到服务器并给我以下错误:
[INFO] [pool-8-thread-15] org.red5.server.so.SharedObject - Deleting shared object moshe because all clients disconnected and it is no longer acquired.