views:

657

answers:

4

I'm trying to write some simple chat client in javascript, but I need a way to update messages in real time. While I could use the xmlhttprequest function, I believe it uses up a TCP/IP port on the server and possibly more importantly, is not allowed on my current hosting package. It doesn't seem like an ideal solution anyway as it seems a bit hacky to constantly have an open connection, and it would be a lot easier if I could just listen on the port and take the data as it comes. I looked on the internet and found lots of references to comet and continuous polling, which are unsatisfactory and lots of people say that javascript isn't really suited to it which I can agree with. Now I've actually learned a bit more about how the internet works however, it seems feasible.I don't need to worry about sending messages so far; I can deal with that, but is there any way to listen on a certain port on javascript?

+1  A: 

You are going to need a third-party library that you can load into the Javascript context.

Javascript itself has no way to do this and its unlikely you could (and certainly you should not) do this inside a browser.

AnthonyWJones
+7  A: 

Listening on a port is not possible in Javascript.

But:

XmlHTTPRequest is possible on your host, as it is a simple HTTP request for a special site like chat.php?userid=12&action=poll&lasttime=31251 where the server prints all new messages since lasttime as the result.

Georg
A: 

Have you considered perhaps building your app in Flex ? You could make use of Flex's XMLSocket class to implement a low-latency chat client - pretty much the sort of thing it was designed to do

Scott Evernden
+1  A: 

Take a look at Comet

Julien
Comet was already mentioned in the question.
andynormancx
the question said references were seen. did NOT say references were actually looked at .. Comet is a perfectly good solution suggestion
Scott Evernden