This is really cool though may be a little bit too low-level for what many of us do on a day-to-day basis.
The web primarily works on top of requests and responses – that is to say that our machines will request data from the the server and the server will respond with the data (or with an error code).
The thing is, not all networks are architected in the same way. Instead, they’re setup such that that the machines will establish a connection via sockets and then share a constant stream of communication.
HTML5Rocks has recently published a project that details the problem and a proposed to solution on how to bring sockets to the web. Generally speaking, the article outlines latency problems, cross-origin communication, proxy servers, use cases, and demos.
The proposed functionality (detailed in JavaScript) would work by first establishing a connection:
[cc lang=”javascript”]
var oConnection = new WebSocket(‘ws://websockets.org:8787/echo’);
[/cc]
Then you’d begin to communicate with the server:
[cc lang=”javascript”]
oConnection.onopen = function () {
connection.send(‘Ping’);
};
oConnection.onerror = function (error) {
console.log(‘WebSocket Error ‘ + error);
};
oConnection.onmessage = function (e) {
console.log(‘Server: ‘ + e.data);
};
[/cc]
Cool, huh? I also love the fact that this is pushing JavaScript, browsers, and server-side code into a new idea. If you’re interested, you can check out the WebSockets API.
Again, not sure how practical this is during your daily work but it’s really neat.
Speak your mind...