Допустим, у меня есть два компьютера.
Они знают общедоступные и частные IP-адреса друг друга через ice4j
.
Один клиент слушает, а другой отправляет какую-то строку.
Я бы хотел, чтобы это происходило с помощью перфорации UPD:
Let A be the client requesting the connection
Let B be the client that is responding to the request
Let S be the ice4j STUN server that they contact to initiate the connection
--
A sends a connection request to S
S responds with B's IP and port info, and sends A's IP and port info to B
A sends a UDP packet to B, which B's router firewall drops but it still
punches a hole in A's own firewall where B can connect
B sends a UDP packet to A, that both punches a hole in their own firewall,
and reaches A through the hole that they punched in their own firewall
A and B can now communicate through their established connection without
the help of S
Было бы неплохо, если бы вы также учли двойной NAT.
Вы можете использовать STUN для обнаружения IP и порта, но вы должны написать свой собственный код, который будет отправлять IP:Port на ваш сервер с помощью техники keepalive
.
Как только один клиент идентифицирует другого с помощью уникального идентификатора на сервере, ему будет предоставлена информация об IP-адресе и порте другого клиента для ввода данных UDP, необходимых для отправки и получения.
На горизонте появляется библиотека для java, проверьте ее:
https://github.com/htwg/UCE#readme