开发者

Connection lost with response.end in node.js

I'm using node.js to have multiple clients. Now, in my code, I'm listening on a por开发者_如何学Got and each time a client connects, I want to send out a broadcast message to all other clients, say. I'm raising a new event each time some new client connects, and I'm sending a response over to him. When I say response.end(), I'm not able to send anything to that specific client after that. However, the browser keeps loading and waiting for the response.end. Is there anyway around this without using socket.io? I know socket.io has its uses, but I really wanted to know if I can do it without socket.io.


I'd say to use two channels in your client; one to receive updates (channel kept open, or frequently querying for updates) and one to refresh the data. It involves some work on your part to restructure the client and the server, but I think using two channels is the cleanest way to solve your problem.


If you don't send the .end() the browser will keep waiting. But if you close the channel you'll not be able to send nothing through it. So, either use socket.io or open a channel via XHR and keep it open for each client to receive messages. Is up to you to adequately frame the messages (implement your applicative protocolo) though. I think Paul is right.


Try long polling, which means letting an ajax request from the browser 'hang' until the server can send something back.

How do I implement basic "Long Polling"?

Using nodejs, you could store the response objects for the clients easily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜