无法使 GAE Channel API 在本地计算机上工作

发布于 2024-10-09 10:10:21 字数 1425 浏览 2 评论 0原文

我正在创建一个小型应用程序来测试 GAE Channel API 的工作原理。我想我已经完成了文档中描述的所有操作,但是当我启动它时,它在 FireFox 错误日志中显示了一个关于开头语法的错误,然后又显示了另一个重复错误,表明找不到该元素。 这是第一个错误信息:

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

这是我的 javascript 代码尝试重复连接的 url,它引发了第二个错误:

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

我通过使用 jQuery $.get 的 JSON 请求获取令牌。然后我运行此代码来获取令牌并打开通道。当我运行 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);

这是 Python 中打开通道的服务器端代码:

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)

我的错误是什么,我能做什么?谢谢!

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 repeatedly 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷血 2024-10-16 10:10:21

Channel API 在 localhost 上的工作方式似乎与在 GAE 托管上的工作方式不同。我把它上传到云端,现在运行良好。虽然看起来它在本地计算机上工作正常,但它在错误日志中重复显示永久性 JS 错误。

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.

梦里寻她 2024-10-16 10:10:21

您可以尝试删除处理程序参数并将处理程序添加为套接字对象的方法,即 socket.onopen = function() {}; 等。这对我有用。但你是对的。根据,您应该能够通过以下方式实现此功能:使用处理程序参数。唔。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文