Code: Select all
<?php
$read_write = "read";
if ($read_write == "read") {
//Initialize the socket
set_time_limit(0);
$address = '127.0.0.1';
$port = 10119;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
echo "socket_create() failed. Reason: " . socket_strerror($sock) . "<BR>";
}
if (($ret = socket_bind($sock, $address, $port)) < 0) {
echo "socket_bind() failed. Reason: " . socket_strerror($ret) . "<BR>";
}
//Start listening on the socket
if (($ret = socket_listen($sock, 5)) < 0) {
echo "socket_listen() failed. Reason: " . socket_strerror($ret) . "<BR>";
}
//Accept an incoming connection
if(($client = socket_accept($sock)) < 0) {
echo "socket_accept() failed. Reason: " . socket_strerror($ret) . "<BR>";
break;
}
//Read whatever was just sent, 1024 bytes' worth. Make this however long you need.
if( false == ($global_string = socket_read($client, 2048))) {
echo "socket_read() failed. Reason: " . socket_strerror($ret) . "<BR>";
break;
}
//Strip whitespace
$global_string = ereg_replace("[ \t\n\r]", "", $global_string).chr(0);
$array = explode(',', $global_string);
print ("Global string before being parsed: $global_string\n<BR>");
print ("Global string after being parsed:<BR>");
$id = $array[0];
$width = $array[1];
$footagecount = $array[2];
$length = $array[3];
print("<BR>");
print ("Serving Client!<BR>");
//print("<textarea wrap='OFF'>$id</textarea>";
print("Coil ID number: $id<BR>");
print("Coil Width: $width<BR>");
print("Footage Count: $footagecount<BR>");
print("Coil Length: $length<BR>");
//Close the connection; Don't leave things like this open...!!
socket_close($client);
//Close the socket itself
socket_close($sock);
} //ends if ("read")
if (isset($_GET['counter'])) {
$counter = $_GET['counter'];
} else {
$counter = 0;
}
$counter++;
echo "just testing... " . $counter . "<br>";
$redirect_page = $_SERVER['PHP_SELF'] . "?counter=" . $counter;
?>
<script language="javascript">
setTimeout("window.location = '<? echo $redirect_page; ?>'", 2000);
</script>Code: Select all
tags when posting PHP code in the forums[/color]