Say we're on a network where only HTTP is allowed, what's the simplest way to use the http
module as net
module (TCP) socket/stream? Between two Node servers, I'd like is to be able to send data using write()
and receive this data with on('data',...)
at the other end continuously. Currently, I can write once to each end then subsequent writes don't seem to send.
Asked
Active
Viewed 612 times
0

jpillora
- 5,194
- 2
- 44
- 56
1 Answers
1
HTTP in its very nature is uni-directional. The best you can get would be two uni-directional channels, without realtime communication.
You can use Server-Sent events(EventSource), which is a part of HTML5 standard. It uses HTTP to transport messages. You should also look at websockets which are similar to tcp sockets. They offer full-duplex realtime communication. They use a different websocket protocol, but can use same ports as http. If websocket is not blocked, you should use it.
Here is a comparison between the two : WebSockets vs. Server-Sent events/EventSource

Community
- 1
- 1

user568109
- 47,225
- 17
- 99
- 123
-
This is in the context of two Node applications, not the browser. I've got [dnode](https://github.com/substack/dnode) (RPC) working over HTTP, though I'm just lacking understanding of how it works exactly, hence I'm looking for a barebones example. Not the answer I'm looking for though thanks for response. Will read through the dnode source for answers... – jpillora Aug 13 '13 at 06:13
-
@jpillora Please update you are working between two node apps in the question. – user568109 Aug 13 '13 at 06:28
-
sorry about that, fixed – jpillora Aug 14 '13 at 00:23