When to use TCP and HTTP in node.js?

Stupid question, but just making sure here:

When should I use TCP over HTTP? Are there any examples where one is better than the other?

+3
source share
2 answers

TCP is full duplex two-way communication. HTTP uses a request / response model. See if you are recording a chat or messaging application. TCP will work much better because you can report this to the client immediately. While with HTTP you should do some tricks, such as a lengthy poll.

However, TCP is just a stream of bytes. You must find another protocol to define your messages. You can use Google ProtoBuffer for this.

+9

HTTP, , , , , , , , , , , , ...

TCP, . , TCP, , .

+1

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


All Articles