繁体   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