Tcp communication under linux-how to realize the communication between two clients, and the server does not forward messages.

has just realized the communication between two clients (tcp protocol under linux). The implementation idea is very simple, that is, one client sends a message, and the server first read to and then write to another client, and that"s it.

after careful consideration, there is a question as to whether it is possible for the server to send another client to read, directly without read, so that the burden on the server can be reduced.

just got in touch with tcp communication for guidance. Give me an idea or just drop a code.

Mar.10,2021

this depends on the network connection of the two clients, in three cases

  1. directly connected, neither side uses NAT (Network address Translation) devices (such as routers)
  2. one side uses a NAT device
  3. both sides use NAT devices

the first two can be directly connected to two clients, and the third depends on whether the NAT device can predict the port, and most of them can also be directly connected.

For more technical details, search for keywords such as "tcp traversal", "tcp hole punching", "nat traversal", "TCP hole" and so on.

references

  1. https://en.wikipedia.org/wiki.
  2. https://en.wikipedia.org/wiki.
  3. python-nat-hole-punching" rel=" nofollow noreferrer "> https://github.com/dwoz/pytho.
Menu