2013-06-01 3 views
1

그래서 다음과 같은 문제가 발생합니다. 지금까지 내가 red5 서버에서 클라이언트에서 메서드를 호출 할 수 있지만 클라이언트에서 메서드를 호출하는 red5 서버에서 작동하지 않습니다. 나는이가 깜박 SYSOUT가 호출되는 서버 측하지만 클라이언트 측의 방법에red5 서버에서 플래시 클라이언트의 메소드를 호출 할 수 없습니다.

지금과 같은 클라이언트 측이 호출되지 않습니다되는 다음 코드

public function onCreationComplete(event:FlexEvent) : void { 


connection = new NetConnection(); 
connection.connect("rtmp://localhost/simpleChat"); 
connection.client = this; 
so = SharedObject.getRemote("sharedMessage"); 
connection.addEventListener(NetStatusEvent.NET_STATUS, onConnectionNetStatus); 
connection.call("addOne", ro, 5); 
    } 


    public function onConnectionNetStatus(event:NetStatusEvent) : void { 

if(event.info.code == "NetConnection.Connect.Success") { 
    Alert.show("Connection Successful","Information"); 
} else { 
    Alert.show("Conection not successful", "Error"); 
} 

     } 

     public function onResult(responder:String): void{ 
Alert.show(responder); 

    } 

    public function onError(e:Object): void{ 
Alert.show("Got an error: " + e.description); 
    } 

    private function onClickSendBtn(event:MouseEvent):void 
    { 

connection.call("broadcastMessageToClients", null, inputTxt.text); 
    } 

    public function receiveBroadcastedMessages(msg:String):void 
    { 
      outputTxtArea.text += msg + "\n"; 
    } 

를, 어떤 문제가있어?

public class Application extends ApplicationAdapter { 

/* 
* The scope object. A statefull object shared between a group of clients connected to the same context path. 
* Scopes are arranged in hierarchical way, so its possible for a scope to have a parent and children scopes. 
* If a client connects to a scope then they are also connected to its parent scope. The scope object is used 
* to access resources, shared object, streams, etc. That is, scope are general option for grouping things in 
* application. The following are all names for scopes: application, room, place, lobby. 
*/ 
private IScope appScope; 


/** {@inheritDoc} */ 
@Override 
public boolean connect(IConnection conn, IScope scope, Object[] params) { 

    // init appScope 
    appScope = scope; 

    // create a sharedobject on server and call it "sharedMessage" under the current scope. 
    createSharedObject(appScope, "sharedMessage", false); 
    return true; 
} 

/** {@inheritDoc} */ 
@Override 
public void disconnect(IConnection conn, IScope scope) { 
    super.disconnect(conn, scope); 
} 

/* Simple method to illustrate how simple is to access the methods on the server side from the client side. 
* if called from the client it adds "1" to the passed argument. 
*/ 
public double addOne(double a) { 

    return a + 1; 
} 

/* Simple method to illustrate how simple is to access the methods on the client side from the server side. 
* Also this uses the SharedObject to send a unified message to all connected clients 
*/ 

public void broadcastMessageToClients(List<String> params) { 

    ISharedObject so = getSharedObject(appScope, "sharedMessage"); 

    System.out.println("broadcastMessageToClients..."); 
    // call receiveMessage method on all connected clients 
    so.sendMessage("receiveBroadcastedMessages", params); // send the received parameter back to all connected clients by calling the "receiveBroadcastedMessages" method on the client side 

} 

답변

0

당신은 공유 객체하지만 SO 서버에 연결되지 않은 클라이언트를 사용하여 클라이언트의 메소드를 호출하는, 아래의 코드는 필요이 코드 그것을

so = SharedObject.getRemote("sharedMessage"); 
co.client = this; //indicate that this class will have the methods invoked by the server 
so.connect(connection); //connect the SO with the server 

작업을 수행하는 방법을 보여줍니다 서버와 성공적으로 연결될 때 호출되므로 onConnectionNetStatus 기능에 추가되어야합니다.

관련 문제