title: Chrome packaged app UDP sockets not working
body: <p>I'm trying to get UDP sockets working for a packaged app using Chrome Canary (currently version 25).  I am pretty confused by the fact the <a href="http://developer.chrome.com/apps/app_network.html" rel="nofollow">UDP example here</a> conflicts with the <a href="http://developer.chrome.com/apps/socket.html" rel="nofollow">reference documentation here</a>.</p>
  
  <p>The official example uses this line:</p>
  
  <pre><code>chrome.socket.create('udp', '127.0.0.1', 1337, { onEvent: handleDataEvent }, ...
  </code></pre>
  
  <p>In Canary using this line results in the error:</p>
  
  <blockquote>
    <p>Uncaught Error: Invocation of form socket.create(string, string,
    integer, object, function) doesn't match definition
    socket.create(string type, optional object options, function callback)</p>
  </blockquote>
  
  <p>Not surprising since that matches the documented form of the function.  (I guess the example is out of date?)  OK, so I try this...</p>
  
  <pre><code>chrome.socket.create('udp', { onEvent: handleDataEvent }, ...
  </code></pre>
  
  <p>Canary complains:</p>
  
  <blockquote>
    <p>Uncaught Error: Invalid value for argument 2. Property 'onEvent':
    Unexpected property.</p>
  </blockquote>
  
  <p>Now I'm confused, especially since this parameter is <a href="http://developer.chrome.com/apps/socket.html#type-CreateOptions" rel="nofollow">undocumented in the reference</a>.  So I just go with this:</p>
  
  <pre><code>chrome.socket.create('udp', {}, ...
  </code></pre>
  
  <p>Now it creates OK, but the following call to <code>connect</code>...</p>
  
  <pre><code>chrome.socket.connect(socketId, function(result) ...
  </code></pre>
  
  <p>...fails with this:</p>
  
  <blockquote>
    <p>Uncaught Error: Invocation of form socket.connect(integer, function)
    doesn't match definition socket.connect(integer socketId, string
    hostname, integer port, function callback)</p>
  </blockquote>
  
  <p>...which is not surprising, since now my code doesn't mention a host or port anywhere, so I guess it needs to be in <code>connect</code>.  So I change it to the form:</p>
  
  <pre><code>chrome.socket.connect(socketId, address, port, function (result) ...
  </code></pre>
  
  <p>At last I can connect and write to the socket OK.  But this doesn't cover reading.</p>
  
  <ul>
  <li>Can someone show me a working example based on UDP that can send &amp; receive, so I can work from that?</li>
  <li>How do I receive data since the example's onEvent handler does not work?  How do I ensure I receive any data on-demand as soon as it arrives without blocking?</li>
  </ul>