views:

21

answers:

3

Is there a way to have a live connection (like for a chat server) with a server using only HTML(5)/JavaScript?

+1  A: 

Due to the nature of HTTP (only clients can start requests), you would need a "Push" server (aka Comet) on the server-side. You'd still only need JS on the client. See:

This can also be implemented with a periodic refresh (polling) if you can't install a Comet engine on the server.

NullUserException
A: 

Yup. AJAX and some server code to handle messages updates is all you need to create just such a system. As @NullUserException noted, something like Comet might make this easier.

Stefan Kendall
ajax just loads pages, I need a truly live "socket" connection.
Bubby4j
You could emulate it. You don't need a live socket to do a chat client. Look at facebook chat; the order of messages isn't guaranteed, but that's because it shows the user's post as soon as they hit enter, rather than when the response returns.
Stefan Kendall
And ajax doesn't just "load pages". It would allow you to make network requests to some server application which would manage reads and writes of the current chat session.
Stefan Kendall
I'm trying to make a virtual world without using flash or any downloads.
Bubby4j
And? If you want to do something like an MMO, you could buffer the actions of other players on the screen, so long as they couldn't conflict with your actions. I don't know that you could implement the efficient network protocol you would need to do a massive real-time game, however.
Stefan Kendall
Ok, thanks. I guess this will work until they invent something better rofl.
Bubby4j
+1  A: 

Apparently FF4, Chrome, and Safari all support Web Sockets.

Here's a firefox example, although I'm not sure the spec is completely finalized yet.

Stefan Kendall