Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8601879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:56:48+00:00 2026-06-12T01:56:48+00:00

After a while I got the first part of the Google Channel API working.

  • 0

After a while I got the first part of the Google Channel API working. Now I have some problems with sending a message from the JavaScript client to the server.
Here is the servlet for the Google Channel API connection:

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
        ChannelService channelService = ChannelServiceFactory.getChannelService();
        String token = channelService.createChannel(user.getUserId());

        FileReader reader = new FileReader("index.html");
        CharBuffer buffer = CharBuffer.allocate(16384);
        reader.read(buffer);
        reader.close();

        String index = new String(buffer.array());
        index = index.replaceAll("\\{\\{ token \\}\\}", token);

        resp.setContentType("text/html");
        resp.getWriter().write(index);
    } else {
        resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
    }

The index.html looks like following:

<script src="/_ah/channel/jsapi"></script>

<body>
    <script type="text/javascript">
        onOpened = function() {
            alert("opened");
        }

        var token = "{{ token }}";
        var channel = new goog.appengine.Channel(token);
        var handler = {
            'onopen' : onOpened,
            'onmessage' : onMessage,
            'onerror' : function() {
            },
            'onclose' : function() {
            }
        };
        var socket = channel.open(handler);
        socket.onopen = onOpened;
        socket.onmessage = onMessage;

        function sendMessage() {
            // Send JSON object to server   
        }
    </script>
    <h1>Google Test Channel API</h1>
    <form>
        <input type="button" value="Send" onclick="sendMessage();">
    </form>
</body>

If I load the application I get the opened alert, I believe the connection is working. Now I would like to send a message to the server, if someone clicks on the button.

I read that I have to use the XMLHttpRequest function with POST or GET. But I won’t pass a new url, I
would just pass a value. Is there a way to send a JSON object to the server?

Something like:

{
    "message": "This is a JavaClient message!"
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:56:49+00:00Added an answer on June 12, 2026 at 1:56 am

    This doesn’t really have much to do with the Chanel API – it’s just a standard xhr call back to the server. You can use standard code like this, or use a library such as jquery like this.

    If you need to parse javascript into JSON use JSON.stringify().

    At the server you can process your request as required, send a response back to the client via standard HTTP or use the Chanel API to send a message not just to the original client, but to all connected clients.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After a while using the website, loading contents, etc.. this message shows Fill: SelectCommand.Connection
I have an unusual problem with my views - after a while of using
After studying the docs for a while, I came up with my first jQuery
I got the following error while trying to alter a column's data type and
I added a launch image to my iPhone app in Xcode, but after while,
After a while I figured out I could bind Shark to the process of
Well after a while of scratching my head and going huh? trying to figure
In my app after a while, there seems to be a huge issue. There
I've written a web app which after a while causes IE 8's memory usage
I'm opening lots of files with fopen() in VC++ but after a while it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.