Problem coding a php server app.
Posted: Mon Jun 20, 2005 7:21 am
I have the following server coded in php. It connects through a socket to a vb6 client and is used to recieve 4 values. It is my intention to update the page each time a new message is sent(which eventually I intend to set to one second) and have the old message erased. The problem I am having is that the only way I can get the page to update is to shut my vb6 client down completely. I wanted to have both applications running and every second or two have the page update with the latest message that was sent. Can anybody see the problem with this code or offer any suggestions on what I can do to get this functionality. I am brand new to php and this is my first program that I have ever wrote so if possible be as specific as can be. thanks.
d11wtq | Please use
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]