簡體   English   中英

使用 FluorineFx 作為客戶端連接 NetConnection 時處理服務器端 RtmpConnection.Invoke()

[英]Handling Server-side RtmpConnection.Invoke() when connecting with NetConnection as a client using FluorineFx

我正在嘗試創建一個基本的控制台應用程序,以便對我們基於 FluorineFx 的 flash 遠程服務器進行壓力測試。

我可以正常連接,但我正在調用的服務器方法調用了這個客戶端 function:

connection.Invoke("onServerDataPush", new string[] { "someParam", "anotherParam" });

我正在努力找出如何將此方法公開給連接。 NetConnection.Call() 方法允許您傳入回調,但其結果始終是 null 並且 NetConnection 調用失敗並出現以下錯誤:

Could not find a suitable method with name onServerDataPush

這是我的客戶端代碼:

class Program
{
    private NetConnection _netConnection;

    static void Main(string[] args)
    {
        var program = new Program();
        program.Connect();
        Console.ReadLine();
    }

    public void Connect()
    {
        _netConnection = new NetConnection();
        _netConnection.ObjectEncoding = ObjectEncoding.AMF3;
        _netConnection.OnConnect += netConnection_OnConnect;
        _netConnection.NetStatus += netConnection_NetStatus;
        _netConnection.Connect("rtmp://localhost:1935/MyApplication");
    }

    void netConnection_OnConnect(object sender, EventArgs e)
    {
        var responder = new Responder<object>(x =>
                                                  {
                                                      var test = x;
                                                  });

        //The NetConnection object is connected now
        _netConnection.Call("MyServerMethod", responder, "someParameter");
    }
    void netConnection_NetStatus(object sender, NetStatusEventArgs e)
    {
        string level = e.Info["level"] as string;
    }
}

通過RtmpClient第 308 行調試終於讓我解決了這個問題。

您必須將NetConnection.Client屬性設置為 class ,其中包含與服務器調用的方法具有相同簽名的方法(在我的情況下, this是因為該方法在 Program 類中)。

    public void onServerDataPush(string type, string json)
    {

    }

FluorineFx 然后使用反射調用該方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM