Listening for port in javascript

I am trying to write some simple chat client in javascript, but I need a way to update messages in real time. Although I could use the xmlhttprequest function, I believe that it uses the TCP / IP port on the server and, perhaps more importantly, is not allowed in my current hosting package. In any case, this is not an ideal solution, since it seems a little inconvenient to constantly open the connection, and it would be much easier if I could just listen to the port and take the data as it arrives. I looked on the Internet and found many links to the comet and continuous polling, which are unsatisfactory, and many people say that javascript is actually not suitable for it, which I can agree with. Now I learned a little more about how the Internet works, it seems doable.I do not need to worry about sending messages so far; I can handle this, but is there any way to listen on a specific port in javascript?

+3
source share
4 answers

Have you considered creating your application in Flex? You can use the Flex XMLSocket class to implement a client with low latency chat - pretty much the kind of things that it was designed to do

-4
source

Port listening is not possible in Javascript.

But:

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

+9
source

, Javascript.

Javascript , (, , ) .

+1
source

Take a look at Comet

+1
source

Source: https://habr.com/ru/post/1703602/


All Articles