DEV Community

loading...

Discussion on: The Power of Pure HTTP – screen share, real-time messaging, SSH and VNC

Collapse
cubiclesocial profile image
cubiclesocial

This is fairly reminiscent of my PHP Cool File Transfer project where I did something similar a few years ago:

github.com/cubiclesoft/php-cool-fi...

One client basically creates a mini-TCP server inside a PHP script on the server and another client somewhere else connects to the mini-TCP server and receives the file as a direct transfer. PHP emits a byte every second to keep the connection alive for the person who is sending the file until the second client connects and accepts or rejects the file. If the file is accepted, then it starts transferring. The web server doesn't store any data - it just sends the data to the other side. The setup of a temporary TCP/IP server per file is somewhat exotic.

There is a slight gotcha with the approach: A GET method caller never finishes as can be seen in the "Simple text messaging" example for Piping Server where the loading indicator never stops spinning. That means onload won't fire in that case. In the instance of a file download, the download manager takes over and handles the request. The solution is to wait until the page has finished loading and then make a XHR request.