Chrome supports TCP & UDP Sockets

Traditionally browsers haven’t been able to make raw socket requests to arbitrary endpoints, mostly due to security concerns. Although the majority of browsers now have WebSockets, the caveat is that the server needs to have specific support for the WebSocket handshake. This has limited the type of protocols and APIs that the browser could communicate with.

However, Chrome’s changing all of that. Canary now has support for raw TCP and UDP sockets in its ‘experimental’ APIs. These features are only available for extensions and, although documented, are hidden for the moment. Having said that, some developers are already creating interesting projects using it, such as this IRC client.

To access this API, you’ll need to enable the experimental flag in your extension’s manifest. Using sockets is pretty straightforward, for example:

chrome.experimental.socket.create('tcp', '127.0.0.1', 8080, function(socketInfo) {
  chrome.experimental.socket.connect(socketInfo.socketId, function (result) {
        chrome.experimental.socket.write(socketInfo.socketId, "Hello, world!");         
    });
});

Although the API is still under flux, already I can see some amazing potential for it, especially when it comes to P2P. A few years ago I did a bit of work concerning firewall tunneling with TCP, which should now be possible in Chrome. This API should lead itself to some interesting applications, like P2P games, collaboration and data transfer.


Incidentally the name Canary comes from the canary that coal miners used to take down the mines. Gases like carbon monoxide used to kill the bird before affecting the miners, giving them enough warning to escape.

 
1,242
Kudos
 
1,242
Kudos

Read this next

Dynamic pagination

Pagination over a constantly changing list is hard. Really hard. In fact it should be one of those computer science problems up there with naming and cache invalidation. The issue especially surfaces in news sites, like Hacker News. The... Continue →