views:

25

answers:

1

I recently wrote a small AJAX-based chat program. The clients ping the server occasionally for new messages and update the view if a change has occurred. Simple.

Is it possible to do this entirely client-side? Could a set of loaded pages identify themselves to other users and send out updates to the other clients? How would this be accomplished? Could it be done entirely in Javascript?

Thanks for your thoughts on this!

+1  A: 

Due to the same-origin policy, your JavaScript is not allowed to contact random third-party servers (or, consequently, other clients).

This is a fundamental part of the JavaScript security model.

The answer is, for better or for worse, that it cannot be done without going through the server or using Flash (which has a server-side way to relax the security).

Borealid
This isn't a good answer as it is both wrong, and not suited to the question. SOP does not prevent you from contacting to other servers (which could be browser instances), and the question revolves around peer-to-peer communication not, client-server communication.
Sean Kinsey
@Sean Kinsey: Have you ever tried to open a connection to a host other than the one delivering your JavaScript? Do that and get back to me. There's a reason that things like web SSH clients and chat programs are written as Java applets.
Borealid
As I am the author of probably the best framework for working around the SOP (http://easyxdm.net/), yes, I've done that and lot more.POST and JSONP are two mechanisms that do what you say is impossible. And the SOP has nothing to do with the domain delivering the javascript, but the domain of the running document.
Sean Kinsey