I wonder if there are any precautions when designing TCP messages.

Asked 2 years ago, Updated 2 years ago, 114 views

Hi, everyone. Until now, I've been working only on HTTP. Attempting to port over TCP. I'd like to apply it to text, image transmission, and security support.

HTTP is based on text, so if you use JSON, the message design is just fine. I don't think TCP can use character-based packaging such as JSON and XML, and I think we need to go to binary. I don't know what to write. I have no idea. I thought it would be out of touch with reality if I set the rules How do you do it in practice? And if the design of the HTTP method has been proven for a long time and you've been insensitive to sticking out, then the design of the TCP message also fails to design it reliably. It's a dilemma. Thank you.

And what I suddenly think is that HTTP overhead may feel small because I don't use a lot of headers because I'm not good enough, but if I just minimize the header by GET or POST, does the overhead differ that much compared to TCP? Aren't you writing a few more letters at the most? Thank you.

tcp

2022-09-22 08:20

1 Answers

In my experience, in most cases, the protocol (HTTP) itself has rarely been overhead. Most bottlenecks come from DB.

HTTP is easy to handle because many of the repetitive parts of the server (tomcat)/client (chrome) are well implemented to make it easy to use, so encoding/decoding, serialization, error/exception processing, etc. do not cross the user (developer) domain. This means, on the contrary, that if you implement it yourself, you have to develop all of the above part by yourself.

It depends on the field, but in my experience, I haven't dealt with binary protocols directly in practice.

If you write it yourself, protobuf, Create protocols using libraries that interconvert binary <-> structured data such as Thrift and attach a typical network like Netty to implement a network.

Aside from the fact that it is difficult to implement directly and the probability of a bug is high, there is a lot of negative productivity compared to what you get. (If you create a server with RAW_TCP, you must also implement the client yourself.)

This is why many mobile games recently implement servers based on HTTP.

p.s: HTTP is not a character-based protocol.


2022-09-22 08:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.