0

我有一个用 Java 运行的简单 Google Protocol Buffers 服务器,我的朋友需要从他的 actionscript 3 应用程序中访问它。我们发现从 *.proto 生成类很容易:

protoc --plugin=protoc-gen-as3=protoc-gen-as3.bat --as3_oututput my.proto

但是对于实际的配置(设置服务器地址和端口)、获取通信通道以及实际调用*.proto中定义的服务,我们都傻眼了。

在 Java 中,借助 的帮助非常容易DuplexTcpClientBootstrap,但是 actionscript 呢?我尝试使用谷歌搜索,但我能找到的所有内容都只与从中生成类有关*.proto,没有调用实际方法/函数的示例。

TIA,我将不胜感激任何链接或示例!

4

1 回答 1

-1

使用“pafau k”,我们有 Java 服务器——它使用 protobuf——但它是写入套接字的。我认为我们有一些误解,因为 flex 可能适用于“http”协议——我说的对吗?

var callService:CallcenterService = new CallcenterService();
var simpleWebRPC:SimpleWebRPC = new SimpleWebRPC("0.0.0.0:1234/");
callService.sendFunction = xmlsock.send;
callService.getDefaults(new EmptyMessage(), function(result:*):void {
  var response:Defaults = result as Defaults;
  if (response){
    trace("RPC call succeeded:", response);
  }
  else{
     trace("RPC call failed:", ErrorEvent(result).text);
  }
});

callService 是从 proto 生成的

message EmptyMessage {}
message Defaults {
    required string xmlContents = 1;
}
service CallcenterService {
    rpc getDefaults (EmptyMessage) returns (Defaults);
}

这是来自 java 服务器的错误:

 com.googlecode.protobuf.pro.duplex.handler.ServerConnectRequestHandler exceptionCaught
WARNING: Exception caught during RPC connection handshake.
com.google.protobuf.InvalidProtocolBufferException: Protocol message tag had invalid wire type.
        at com.google.protobuf.InvalidProtocolBufferException.invalidWireType(InvalidProtocolBufferException.java:78)
        at com.google.protobuf.UnknownFieldSet$Builder.mergeFieldFrom(UnknownFieldSet.java:498)
        at com.google.protobuf.GeneratedMessage$Builder.parseUnknownField(GeneratedMessage.java:438)
        at com.googlecode.protobuf.pro.duplex.wire.DuplexProtocol$WirePayload$Builder.mergeFrom(DuplexProtocol.java:2565)
        at com.googlecode.protobuf.pro.duplex.wire.DuplexProtocol$WirePayload$Builder.mergeFrom(DuplexProtocol.java:2450)
        at com.google.protobuf.AbstractMessage$Builder.mergeFrom(AbstractMessage.java:300)
        at com.google.protobuf.AbstractMessage$Builder.mergeFrom(AbstractMessage.java:238)
        at com.google.protobuf.AbstractMessageLite$Builder.mergeFrom(AbstractMessageLite.java:202)
        at com.google.protobuf.AbstractMessage$Builder.mergeFrom(AbstractMessage.java:738)
        at com.google.protobuf.AbstractMessage$Builder.mergeFrom(AbstractMessage.java:238)
        at org.jboss.netty.handler.codec.protobuf.ProtobufDecoder.decode(ProtobufDecoder.java:101)
        at org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:72)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302)
        at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)
        at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)
        at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261)
        at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)
        at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:281)
        at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:201)
        at org.jboss.netty.util.internal.IoWorkerRunnable.run(IoWorkerRunnable.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source) 
于 2013-05-29T12:13:07.043 回答