title: why so much XHR polling when using app engine Channel API
body: <p>I am trying to use the App Engine <a href="https://developers.google.com/appengine/docs/python/channel/?csw=1#Python_Overview" rel="nofollow">Channel API</a> to avoid polling for updates in my client. The problem is that I see an continuous stream of XHR packets sent in the Chrome console after starting a socket. They all say:</p>
  
  <pre><code>XHR finished loading: GET "http://localhost:8080/_ah/channel/devcommand=poll&amp;channel=xxxOMITTEDxxx-channel-yyyOMITTEDyyy-zzzOMITTEDzzz-1&amp;client=1". jsapi:5406goog.net.XhrIo.send jsapi:5406goog.net.XhrIo.send jsapi:5352goog.appengine.DevSocket.poll_
  </code></pre>
  
  <p>I would not expect any XHR messages until the server tries to send a message. I am using the Python dev_appserver. </p>
  
  <p>Maybe I am doing something wrong in my Javascript. I am successfully requesting a token from the server. When my client receives the token, I start the socket like this:</p>
  
  <pre><code>function listen_to_channel(msg) {
    console.log('--- server response to channel request: ' + JSON.stringify(msg));
  
    // open a channel socket
    var channel = new goog.appengine.Channel(msg.token);
  
    var socket = channel.open();
    socket.onopen = function(){ console.log('socket.onopen')};
    socket.onmessage = function(msg){ console.log('socket.onmessage: ' + msg.data)};
    socket.onerror = function(err){ console.log('socket.onerror: ' + err.description + ', ' + err.code)};
    socket.onclose = function(){ console.log('socket.onclose')};
  }
  </code></pre>
  
  <p>I run that code from jQuery, like so:</p>
  
  <pre><code>$(document).ready(function() {
      $.get('/admin/channel', {clientID:1}, listen_to_channel, 'json')
  });
  </code></pre>
  
  <p>I link the dependencies like so:</p>
  
  <pre><code>&lt;head&gt;
    &lt;script type="text/javascript" src="/_ah/channel/jsapi"&gt;&lt;/script&gt;
    &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script src="javascript/admin.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>The example code is clear that the socket should be created within the  tag of the HTML DOM. Is this the cause of my problem? If so, what does creating the socket within the  tag do differently?</p>