Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

Take a look at Comet

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top