Can I make a hole-punch using normal PHP script on apache server?
<p>There's a concept, maybe a hack, that I've been troubling myself about a long time. What I thought is that essentially, <strong>TCP connection socket is a variable</strong>. It contains some information about your target, which is represented by some specific bytes in your program's memory. And <strong>bytes can be sent to other computers over the internet</strong>.</p>

<p>That concept should allow for a public server to establish direct connection between two private (firewalled or behind router) computers. After googling for a while, I found that this concept indeed exists and is called <a href="https://en.wikipedia.org/wiki/Hole_punching_%28networking%29" rel="nofollow noreferrer">Hole punching</a>.</p>

<p>It's really different from proxy. Have a look - this is typical proxy/relay connection:</p>

<p><img src="https://i.stack.imgur.com/AkOka.png" alt="image description"></p>

<p>The data flows through public server. The green circles represent the socket connections between devices, the blue line is the flow of data.</p>

<p>Now what it the server sends socket A to device B and vice versa?</p>

<p><img src="https://i.stack.imgur.com/UufEs.png" alt="image description"></p>

<p>Suddenly, both devices have each other's "address" and can send any information to each other:</p>

<p><img src="https://i.stack.imgur.com/vXZDW.png" alt="image description"></p>

<p>My question is: Does PHP script allow to get the information needed to share that socket info? How to prevent the socket from being terminated after 30 second PHP time limit?</p>