我在应用程序初始化期间通过一系列 ajax 调用打开了一个通道:
getToken = function () {
xhr = new XMLHttpRequest();
xhr.open("GET", "/game?action=getChannelToken", true);
xhr.send(null);
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status==200) {
connect(xhr.responseText);
}
};
};
小服务程序:
ChannelService channelService = ChannelServiceFactory.getChannelService();
channelToken = channelService.createChannel(uid);
然后将令牌返回给 javascript,用于:
connect = function (token) {
// alert ("connect");
var channel = new goog.appengine.Channel(token);
var socket = channel.open();
socket.onopen = onOpened;
socket.onmessage = onMessage;
socket.onerror = onError;
socket.onclose = onClose;
};
我收到此错误:
警告:/_ah/channel/dev com.google.appengine.api.channel.dev.LocalChannelFailureException:找不到应用程序密钥 null 的通道。
频道创建部分很简单,所以我不明白问题出在哪里。
System.out.println (channelToken);
返回类似的东西
通道--rrmk8i-100002139544068
(100002139544068 是我用来创建频道的 uid),所以它似乎返回了一个真实的令牌。此外,channelService.sendMessage(msg);
(使用与以前相同的 uid),发送消息没有任何问题。
有谁知道为什么会这样?我正在使用 eclipse 3.5.2、GAE/J 1.4.2 和 ubuntu 10.10
谷歌搜索该异常,我在这里只找到了一个讨论: http ://groups.google.com/group/google-appengine-java/browse_thread/thread/19f250b1ff0e4342
但是更改var channel = new goog.appengine.Channel(token);
为var channel = new goog.appengine.Channel(uid);
并没有解决任何问题(据我所知,它不应该)