admin管理员组文章数量:1022612
I'm looking for the fastest way for multiple users on different machines to interact, and I think it's by using the server as the munication facilitator. So user A and user B both create a socket connection to the server of some kind and whenever user A does something it sends a message to the server, which then sends a message to user B.
The later part is what I'm trying to do in javascript. I've already done it in flash with XMLSocket, so is there an equivalent functionality in javascript?
PS: I found EventSource() here: / , but I'm not sure if it's implemented by browsers yet.
Edit: Ideally it would be used for things like chat applications where real-time events are needed, so using ajax calls every X seconds would be too slow. Why hasn't W3C added such an HTML 5 object yet, since it seems to be very useful.
I'm looking for the fastest way for multiple users on different machines to interact, and I think it's by using the server as the munication facilitator. So user A and user B both create a socket connection to the server of some kind and whenever user A does something it sends a message to the server, which then sends a message to user B.
The later part is what I'm trying to do in javascript. I've already done it in flash with XMLSocket, so is there an equivalent functionality in javascript?
PS: I found EventSource() here: http://dev.w3/html5/eventsource/ , but I'm not sure if it's implemented by browsers yet.
Edit: Ideally it would be used for things like chat applications where real-time events are needed, so using ajax calls every X seconds would be too slow. Why hasn't W3C added such an HTML 5 object yet, since it seems to be very useful.
Share Improve this question edited Jun 8, 2009 at 12:46 manixrock asked Jun 8, 2009 at 12:12 manixrockmanixrock 2,5534 gold badges24 silver badges29 bronze badges 1- 1 The W3C hasn't added an HTML5 object for it because HTML5 would be the wrong place to include it. It would have to be included in the JavaScript standard, not the HTML standard. – Dan Herbert Commented Jun 8, 2009 at 13:59
5 Answers
Reset to default 3The situation here's changed a bit.
See screenshot:
All major browsers except IE - including Firefox, Webkit (i.e. Chrome plus Desktop/Mobile Safari), and Opera have had a chance to implement the HTML5 implementation of server-side push.
This is great news for iPhone/iPad/Android web app developers, but not so momentous for the rest of the world that is still struggling with poor web standards implementation of IE6-8, and Firefox playing catch-up.
The current situation is that if you want cross-browser support, then the Comet server described by Dan (or an iFrame/xmlhttp polling repeatedly) is still your best option.
You might want to look into Comet (reverse Ajax) for generating server-sent events. As far as I know, no browsers implement EventSource()
.
The Ajaxian also has a good article about Comet including examples such as GTalk.
This option can be considered "bad" because it keeps a connection constantly open with the server which can increase load.
You could consider polling by making an Ajax request every X seconds to check for an update. As mentioned in the Ajaxian article I included, 37Signals polls every 3 seconds for real-time chat and that seems to work "good enough" for them.
One way to do this is to use a flash-javascript socket bridge. There are several implementations of this. I've used this one. It is very fast! Another benefit to this is that you won't have to change your server to make it work.
Well, you have ajax. That does not keep an open connection (except in the case of keep-alive connections, but js cannot work with them like sockets). You send an XML-encoded message to the server from A, and B regularly polls the server for messages. The server would have to keep an inbox for each client.
Flash-JavaScript? How about Java-JavaScript (I.e. LiveConnect). I'm creating a page right now where I use a hidden Java applet (width and height 1 pixel with the same color as the background) to have full control over all the good low-level socket munication and from the applet call a JavaScript function to make updates to the web page DOM/HTML when new data bees available. The Java SDK is free. The Flash SDK isn't, last time I tried to find where to download it.
I'm looking for the fastest way for multiple users on different machines to interact, and I think it's by using the server as the munication facilitator. So user A and user B both create a socket connection to the server of some kind and whenever user A does something it sends a message to the server, which then sends a message to user B.
The later part is what I'm trying to do in javascript. I've already done it in flash with XMLSocket, so is there an equivalent functionality in javascript?
PS: I found EventSource() here: / , but I'm not sure if it's implemented by browsers yet.
Edit: Ideally it would be used for things like chat applications where real-time events are needed, so using ajax calls every X seconds would be too slow. Why hasn't W3C added such an HTML 5 object yet, since it seems to be very useful.
I'm looking for the fastest way for multiple users on different machines to interact, and I think it's by using the server as the munication facilitator. So user A and user B both create a socket connection to the server of some kind and whenever user A does something it sends a message to the server, which then sends a message to user B.
The later part is what I'm trying to do in javascript. I've already done it in flash with XMLSocket, so is there an equivalent functionality in javascript?
PS: I found EventSource() here: http://dev.w3/html5/eventsource/ , but I'm not sure if it's implemented by browsers yet.
Edit: Ideally it would be used for things like chat applications where real-time events are needed, so using ajax calls every X seconds would be too slow. Why hasn't W3C added such an HTML 5 object yet, since it seems to be very useful.
Share Improve this question edited Jun 8, 2009 at 12:46 manixrock asked Jun 8, 2009 at 12:12 manixrockmanixrock 2,5534 gold badges24 silver badges29 bronze badges 1- 1 The W3C hasn't added an HTML5 object for it because HTML5 would be the wrong place to include it. It would have to be included in the JavaScript standard, not the HTML standard. – Dan Herbert Commented Jun 8, 2009 at 13:59
5 Answers
Reset to default 3The situation here's changed a bit.
See screenshot:
All major browsers except IE - including Firefox, Webkit (i.e. Chrome plus Desktop/Mobile Safari), and Opera have had a chance to implement the HTML5 implementation of server-side push.
This is great news for iPhone/iPad/Android web app developers, but not so momentous for the rest of the world that is still struggling with poor web standards implementation of IE6-8, and Firefox playing catch-up.
The current situation is that if you want cross-browser support, then the Comet server described by Dan (or an iFrame/xmlhttp polling repeatedly) is still your best option.
You might want to look into Comet (reverse Ajax) for generating server-sent events. As far as I know, no browsers implement EventSource()
.
The Ajaxian also has a good article about Comet including examples such as GTalk.
This option can be considered "bad" because it keeps a connection constantly open with the server which can increase load.
You could consider polling by making an Ajax request every X seconds to check for an update. As mentioned in the Ajaxian article I included, 37Signals polls every 3 seconds for real-time chat and that seems to work "good enough" for them.
One way to do this is to use a flash-javascript socket bridge. There are several implementations of this. I've used this one. It is very fast! Another benefit to this is that you won't have to change your server to make it work.
Well, you have ajax. That does not keep an open connection (except in the case of keep-alive connections, but js cannot work with them like sockets). You send an XML-encoded message to the server from A, and B regularly polls the server for messages. The server would have to keep an inbox for each client.
Flash-JavaScript? How about Java-JavaScript (I.e. LiveConnect). I'm creating a page right now where I use a hidden Java applet (width and height 1 pixel with the same color as the background) to have full control over all the good low-level socket munication and from the applet call a JavaScript function to make updates to the web page DOM/HTML when new data bees available. The Java SDK is free. The Flash SDK isn't, last time I tried to find where to download it.
本文标签: Javascript Serverside EventsStack Overflow
版权声明:本文标题:Javascript Server-side Events - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745557251a2155950.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论