开发者

GAE/J Channel API exception even though messages go through?

I open a channel during the app initialization through a series of ajax calls:

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

Servlet:

ChannelService channelService = ChannelServiceFactory.getChannelService();
channelToken = channelService.createChannel(uid);

The token is then returned to the ja开发者_Python百科vascript for:

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

I'm getting this error:

WARNING: /_ah/channel/dev com.google.appengine.api.channel.dev.LocalChannelFailureException: Channel for application key null not found.

The channel creation part is very simple, so I do not understand where is the problem. System.out.println (channelToken); returns something like

channel--rrmk8i-100002139544068

(100002139544068 is the uid I used to create the channel), so it seems to return a real token. Moreover, channelService.sendMessage(msg); (using the same uid as before), sends the message without any problem.

Does anyone have any idea why this is happening? I'm using eclipse 3.5.2, GAE/J 1.4.2 and ubuntu 10.10

Googling for that exception I found only one discussion here: http://groups.google.com/group/google-appengine-java/browse_thread/thread/19f250b1ff0e4342

but changing var channel = new goog.appengine.Channel(token); to var channel = new goog.appengine.Channel(uid); did not solve anything (and, from what I understand, it shouldn't)


I can think of two reasons this could be happening:

  1. You're restarting the dev_appserver.py while your client is still running. Because the client will be polling with an "old" token that the dev_appserver doesn't know about, it will throw this error. If this is the case, just refresh your client page after restarting the dev_appserver (or otherwise force it to request a new token).

  2. connect() is being called with an invalid token. It sounds like you've ruled that out but if the above isn't true it might be worth double-checking.

You can see what token the client is polling with you can open up Firebug or the Chrome dev console and look for requests to a path like this:

http://localhost:8080/_ah/channel/dev?command=poll&channel=channel-1503856530-alpha-token&client=1

The channel-1503856530-alpha-token part of that URL is the token passed to "new goog.appengine.Channel()".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜