Could someone please show me a simple example of how to push data from a server '192.168.0.x' to a client machine '192.168.0.y'.
So that even while the client is busy working, another window could popup, or it could interupt the client and go to a specific url etc
I have tried this site:
http://jpspan.sourceforge.net/wiki/doku ... ppets:push
I created a client.php with this code:
Code: Select all
<!DOCTYPE HTML PUBLIC "e;-//W3C//DTD HTML 4.0 Transitional//EN"e;>
<html>
<head>
<title> Server Push with XmlHttpRequest </title>
</head>
<script type="e;text/javascript"e;>
<!--
var xmlhttp = new XMLHttpRequest();
// Tell XmlHttpRequest to expect a multipart response
xmlhttp.multipart = true;
function acceptResponse(event) {
// event.target is the instance of XmlHttpRequest
document.getElementById('result').innerHTML = event.target.responseText
}
function start() {
// Modify the URL to point at your server
xmlhttp.open("e;GET"e;,"e;http://192.168.0.x/server.php"e;,true);
xmlhttp.onload = acceptResponse;
xmlhttp.send(null);
}
function stop() {
xmlhttp.abort()
}
-->
</script>
<body>
<h1>XmlHttpRequest Server Push Example</h1>
<p><a href="e;javascript:start()"e;>Start</a> : <a href="e;javascript:stop()"e;>Stop</a>
<br>
Server Clock: <span id="e;result"e;></span>
</body>
</html>Code: Select all
require_once 'class.serverPush.php';
$SP = & new HTTP_ServerPush();
$SP->open();
while ( true ) {
$SP->push(date('H:i:s'),'text/plain');
sleep(1);
}Code: Select all
/**
* Class to implement server push connections with multipart/x-mixed-replace
* Note this is only supported by Mozilla (
* @see http://wp.netscape.com/assist/net_sites/pushpull.html
* @see http://www.xulplanet.com/tutorials/mozs ... erpush.php
*/
class HTTP_ServerPush {
/**
* Tracks whether the shutdown is handled by PHP or by the class's user
* @var boolean
* @access private
*/
var $shutdown;
/**
* Begin the server push session
* @var int (default = 0 [infinite]) time limit for PHP script execution
* @var boolean (default TRUE) whether PHP should handle shutdown (and sending closing content)
* @return void
* @access public
*/
function open($time_limit=0, $shutdown = TRUE) {
$this->shutdown = $shutdown;
$contentType = "multipart/x-mixed-replace; boundary={$GLOBALS['_HTTP_SERVERPUSH_BOUNDARY']}";
header ("Content-type: $contentType");
ob_implicit_flush ();
set_time_limit($time_limit);
if ( $shutdown ) {
register_shutdown_function('HTTP_ServerPush_Shutdown');
}
}
/**
* Push some content to replace the previously send content
* @var string content (e.g. a web page)
* @var string content type (mime)
* @return void
* @access public
*/
function push($content,$contentType = 'text/html') {
echo "--{$GLOBALS['_HTTP_SERVERPUSH_BOUNDARY']}\r\n";
echo "Content-type: $contentType\r\n\r\n";
echo $content."\r\n";
}
/**
* Close the HTTP server push session - you need to call this if you explicitly disable
* shutdown behaviour when calling open
* @return void
* @access public
*/
function close() {
if ( !$this->shutdown ) {
HTTP_ServerPush_Shutdown();
}
}
}I then click on the start hyperlink, which is supposed to get the server time pushed to it.
I don't know if I'm going about this in the right way. Also, if anyone knows it there is a non-javascript server push code somewhere.