Problem coding a php server app.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrobertson
Forum Newbie
Posts: 2
Joined: Mon Jun 20, 2005 7:19 am

Problem coding a php server app.

Post by mrobertson »

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.

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>
d11wtq | Please use

Code: Select all

tags when posting PHP code in the forums[/color]
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Use

Code: Select all

tags: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url]

It sounds to me like a problem with the vB client not updating.  If the php part works once, it should work again.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you looked into XMLHttp?
Post Reply