从FCS/FMS迁移到red5的指南(3)

 

 
Remoting client

远程调用客户端

RemotingClient中定义了所有需要通过远程调用协议调用的函数

下面的代码可以做为怎样使用远程调用客户端的例子:

import org.red5.server.net.remoting.RemotingClient;
 
String url = "http://server/path/to/service";
RemotingClient client = new RemotingClient(url);
Object[] args = new Object[]{"Hello world!"};
Object result = client.invokeMethod("service.remotingMethod", args);
// Now do something with the result
 
 

默认情况下,每次调用的超时时间是30秒,不过这个值能通过给构造函数传递第二个参数被改变, 而且这个最大超时间的设置单位是毫秒

The remoting headers AppendToGatewayUrlReplaceGatewayUrl andRequestPersistentHeader are handled automatically by the Red5 remoting client.

这个远程调用的消息头AppendToGatewayUrlReplaceGatewayUrl andRequestPersistentHeader 能自动被red5的远程调用客户端处理

一些在服务端被调用的函数可能耗费比较长的时间才能完成,因此最好是用异步的方式执行调用,避免在Red5线程中死锁。所以一个在IRemotingCallback中实现的对象必须被做为附件的参数传递,示例代码如下:
 
import org.red5.server.net.remoting.RemotingClient;
import org.red5.server.net.remoting.IRemotingCallback;
 
public class CallbackHandler implements IRemotingCallback {
 
  void errorReceived(RemotingClient client, String method,
                     Object[] params, Throwable error) {
      // An error occurred while performing the remoting call.
  }
  
  void resultReceived(RemotingClient client, String method,
                      Object[] params, Object result) {
      // The result was received from the server.
  }
}
 
String url = "http://server/path/to/service";
RemotingClient client = new RemotingClient(url);
Object[] args = new Object[]{"Hello world!"};
IRemotingCallback callback = new CallbackHandler();
client.invokeMethod("service.remotingMethod", args, callback);

你可能感兴趣的:(.net)