使用 FluorineFx 作为客户端连接 NetConnection 时处理服务器端 RtmpConnection.Invoke()
我正在尝试创建一个基本的控制台应用程序,以便对我们基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过
RtmpClient
第 308 行调试终于让我解决了这个问题。您必须将 NetConnection.Client 属性设置为包含与服务器调用的方法具有相同签名的方法的类(在我的例子中,该方法是在程序类中)。
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 casethis
as the method is in the Program class).FluorineFx then calls the method using reflection.