使用 FluorineFx 作为客户端连接 NetConnection 时处理服务器端 RtmpConnection.Invoke()

发布于 2024-11-15 02:20:36 字数 1552 浏览 2 评论 0原文

我正在尝试创建一个基本的控制台应用程序,以便对我们基于 FluorineFx 的闪存远程处理服务器进行压力测试。

我可以很好地连接,但我调用的服务器方法会调用此客户端函数:

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;
    }
}

I am trying to create a basic console app in order to stress test our FluorineFx based flash remoting server.

I can connect fine but the server method I am calling invokes this client-side function:

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

I am struggling to find out how I can expose this method to the connection. The NetConnection.Call() method allow you to pass in a callback but the result of this is always null and the NetConnection call fails with the following error:

Could not find a suitable method with name onServerDataPush

Here is my client-side code:

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;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心清如水 2024-11-22 02:20:36

通过 RtmpClient 第 308 行调试终于让我解决了这个问题。

您必须将 NetConnection.Client 属性设置为包含与服务器调用的方法具有相同签名的方法的类(在我的例子中,该方法是在程序类中)。

    public void onServerDataPush(string type, string json)
    {

    }

FluorineFx 然后使用反射调用该方法。

Debugging through RtmpClient line 308 finally allowed me to solve this.

You must set the NetConnection.Client property to the class that contains a method of the same signature as the one being invoked by the server (in my case this as the method is in the Program class).

    public void onServerDataPush(string type, string json)
    {

    }

FluorineFx then calls the method using reflection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文