开发者

Can't make GAE Channel API work on local computer

I am creating a small application to test how GAE Channel API works. I think I have done all as it's described in the documentation but when I launch it, it shows an error in FireFox error log about syntax in the beginning and then another repeating error that an element wasn't found that. Here is the first error info:

Source: http://127.0.0.1:8080/_ah/channel/dev?command=connect&channel=channel-773698929-185804764220139124118
Line 1, symbol 1

Here is the url where my javascript code tries to connect re开发者_StackOverflow社区peatedly and it raises the second error:

http://127.0.0.1:8080/_ah/channel/dev?command=poll&channel=channel-2071442473-185804764220139124118&client=1

I get the token through a JSON request with jQuery $.get. Then I run this code to get the token and open the channel. The error begins to show just when I run socket = channel.open(handler):

var response = JSON.parse(data);
        var token = response.token.toString();
        channel = new goog.appengine.Channel(token);
        var handler = {
            'onopen': onOpened,
            'onmessage': onMessage,
            'onerror': function() {
            },
            'onclose': function() {
            }
        };

        socket = channel.open(handler);

Here is the server side code in Python to open the channel:

class OpenChannel(webapp.RequestHandler):
    def get(self):
        user = users.get_current_user()
        token = channel.create_channel(user.user_id())
        serialized = json.dumps({'token': token})
        self.response.headers['Content-Type'] = "application/json"
        self.response.out.write(serialized)

What's my error and what can I do? Thanks!


It seems that Channel API works on localhost different way than on GAE hosting. I uploaded it to the cloud and it works well now. Though it looks like it working fine on the local computer, it shows permanent JS error repeating in the error log.


You could try removing the handler argument and adding the handlers as methods of the socket object i.e. socket.onopen = function() {}; etc. That worked for me. But you are right. According to this, you should be able to get this working by using the handler argument. Hmm.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜