unable to create new channel in javascript of channel API

Here is my python file

import os
from google.appengine.api import channel
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
import logging

token = 'default'

class SendMessage(webapp.RequestHandler):
    def post(self):
        logging.info('Sending messgae with tokens : ' + token)
        channel.send_message(token,'Hello from the server')

class MainPage(webapp.RequestHandler):
    def get(self):
        global token
        token = channel.create_channel('ram')
        logging.info('Token : ' + token)
        channel.send_message(token,'Hello from the server')
        template_values = {'token': token}
        path = os.path.join(os.path.dirname(__file__), 'index.html')

        self.response.out.write(template.render(path, template_values))

application = webapp.WSGIApplication([
    ('/', MainPage),('/sendmessage',SendMessage)], debug=True)

def main():

if __name__ == "__main__":

and HTML file

        <script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
    <body >
            var state = {
                token: '{{ token }}'
            var token = state.token;
            openChannel = function () {
                var channel = new goog.appengine.Channel(token.toString());
                var socket = channel.open();
                socket.onopen = function () {
                socket.onmessage = function () {
                socket.onerror = function () {
                socket.onclose = function () {

            sendMessage = function () {

                var xhr = new XMLHttpRequest();
                xhr.open('POST', '/sendmessage', true);
        Hi All, <br>
        <button onclick="openChannel()">Open Connection</button>
        <button onclick="sendMessage()">Send Message</button>

On the page there is Open Connection button that create the channel to the created token on server side. Now when I click on this button it flashes the error alert and then close alert. I want to make a channel and send message from server to the browser.

Am I missing something ?



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.