User:Woozle/two-way http
This is mainly a quick tabdump of pages I had open while trying to figure out how to let a server push updates to a web browser, as described here:
- JavaScript now has all the JavaScript liniks
- WebSockets:
- websockify
- http://www.spice-space.org/ -- part of the toolkit for doing a virtual terminal via web (I think)
- http://stackoverflow.com/questions/11334320/using-websocket-on-apache-server
- https://code.google.com/p/phpwebsocket/
- https://code.google.com/p/phpwebsocket/source/browse/trunk/%20phpwebsocket/server.php - can this be adapted to just serve the output of a CLI script?
- http://php.net/manual/en/function.socket-create.php - PHP socket functions
- https://code.google.com/p/phpwebsocket/source/browse/trunk/%20phpwebsocket/server.php - can this be adapted to just serve the output of a CLI script?
- https://code.google.com/p/phpwebsocket/
- Proxying with Apache:
- https://www.meteor.com/tutorials/blaze/creating-an-app -- need to be able to serve this over https, somehow
- http://php.net/manual/en/function.header.php - sending http headers
Code
This didn't work (in .htaccess):
ProxyPass /meteor http://localhost:3000
ProxyPassReverse /meteor http://localhost:3000
This does work, for the front end: <php>
$out = '
';
$out .= <<<__END__
<script> console.log("GOT TO HERE");
var ctMain = document.getElementById('main'); ctMain.innerHTML = "Fetching page...
";
// req.onload = function (event) {
function evPageLoaded(event) { ctMain.innerHTML = req.responseText + 'L'; }; function evPageUpdate(event) { ctMain.innerHTML = req.responseText + 'U'; }; function evPageFailed(event) { ctMain.innerHTML = req.responseText + 'Houston, we have a problem.'; } function evPageKilled(event) { ctMain.innerHTML = req.responseText + 'Cancelled'; } var req = new XMLHttpRequest(); req.addEventListener("progress", evPageUpdate); req.addEventListener("load", evPageLoaded);
// req.addEventListener("error", transferFailed); // req.addEventListener("abort", transferCanceled);
// req.open('get', 'https://vbz.net/phpinfo.php', true); // req.open('get', 'https://vbz.net/ajax', true);
req.open('get', 'http://vbz.net:3000', true); req.send();
</script> __END__; return $out; </php>
This gets dumped all at once when sent via Apache, but displays incrementally via CLI: <php> if (ob_get_level() == 0) ob_start();
//header('Content-Type: Multipart/mixed; boundary="___BOUNDARY___";'); header('Content-Type: multipart/x-mixed-replace; boundary="___BOUNDARY___";');
echo "\n"; echo "___BOUNDARY___\n"; echo "Content-Type: text/html; charset=utf-8\n"; echo "\n";
for ($count = 1; $count <= 10; $count++) {
echo "\n"; echo "___BOUNDARY___\n"; echo "Content-Type: text/html; charset=utf-8\n"; echo "\n"; echo "$count
\n"; //echo str_pad(,8192)."\n"; ob_flush(); flush(); usleep(500000);
} echo "___BOUNDARY___\n"; ob_end_flush(); </php>