admin管理员组文章数量:1430537
I'm now creating a script on my website, which will need a bi-direction connection (the script is a chat room window). But we don't want to create a socket. Instead, we want to make client(the script) and server both have ability of sending http request to each other.
(BTW, the website server and script server are two different servers)
It is very easy for client(the script) to send http request to our server. But it is a big problem for the client(the script) to listen to http requests.
I have done some search but found nothing, maybe this requirement is so weird that seldom been used? Is it possible for a script which embeded in webpage that listen for http request?
Thanks!
I'm now creating a script on my website, which will need a bi-direction connection (the script is a chat room window). But we don't want to create a socket. Instead, we want to make client(the script) and server both have ability of sending http request to each other.
(BTW, the website server and script server are two different servers)
It is very easy for client(the script) to send http request to our server. But it is a big problem for the client(the script) to listen to http requests.
I have done some search but found nothing, maybe this requirement is so weird that seldom been used? Is it possible for a script which embeded in webpage that listen for http request?
Thanks!
- Use WebSockets and keep a persistant connection open. – Phylogenesis Commented Aug 15, 2016 at 13:24
- 1 if you dont want socket, try this html5rocks./en/tutorials/eventsource/basics – Ja9ad335h Commented Aug 15, 2016 at 13:30
- Great! That's almost what I am finding! But seems like IE/edge does not support that!? – Hubert Lin Commented Aug 15, 2016 at 13:39
- What's the reason you don't want to create a socket? – deceze ♦ Commented Aug 15, 2016 at 13:44
- That's a bit plicated. If I can, I would choose to use socket create connection. But I need a back up plan if my teammate cannot create a server which capable of creating socket. – Hubert Lin Commented Aug 15, 2016 at 14:25
1 Answer
Reset to default 4In order to receive an HTTP request, you must:
- have a publicly accessible IP address
- have an open port, publicly accessible
- bind a program to that port to listen for HTTP requests
Browsers fall down on all three counts. You cannot expect that all of your clients have a publicly reachable, unblocked IP address with specifically the port open that you want. But even if that were the case, there's no way for the browser to listen to ining requests; there's no API to do that in the browser, partly because the browser is an HTTP client and not a server, partly because offering such an API would probably provide an extremely powerful API to all sorts of attackers, and partly because it oftentimes is useless anyway because the browser cannot be reached anyway (see point 1).
So, no, you cannot turn the browser into an HTTP server.
Use WebSockets.
本文标签: javascriptListen to http request on webpageStack Overflow
版权声明:本文标题:javascript - Listen to http request on webpage - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745506824a2661282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论