Chrome supports TCP & UDP Sockets
1 min read

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', '', 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.

Enjoying these posts? Subscribe for more