<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2745.2800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I am developing a sockets interface, in PHP running
under Fedora Core 5, to receive requests and return data. See below is the
program in its most basic form. It accepts requests and returns data
but the program waits on the socket_read and only moves on when either
data is received or the sending system terminates the connection. This means
that other users/systems cannot gain access. I have hunted around the
Internet and tried various combinations without success. </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Any suggestions?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thanks, Brendan </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>#!/usr/local/bin/php -q<BR><?php<BR>// Simple
sockets receive program<BR>error_reporting (E_ALL);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>/* Allow the script to hang around waiting for
connections. */<BR>set_time_limit (0);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>/* Turn on implicit output flushing so we see what
we're getting<BR> * as it comes in. */<BR>ob_implicit_flush ();<BR>print
"Started\n";</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>$address = '192.168.40.19';<BR>// PORT NEEDS TO BE
PERMITTED THROUGH FIREWALL<BR>$port = 21244;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>if (($sock = socket_create (AF_INET, SOCK_STREAM,
0)) < 0) {<BR> echo "socket_create() failed: reason: " .
socket_strerror ($sock) . "\n";<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>if (($ret = socket_bind ($sock, $address, $port))
< 0) {<BR> echo "socket_bind() failed: reason: " .
socket_strerror ($ret) . "\n";<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>if (($ret = socket_listen ($sock, 5)) < 0)
{<BR> echo "socket_listen() failed: reason: " .
socket_strerror ($ret) . "\n";<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>do {<BR>print "In loop\n";<BR> if
(($msgsock = socket_accept($sock)) < 0)
{<BR> echo "socket_accept() failed:
reason: " . socket_strerror ($msgsock) .
"\n";<BR> break;<BR>
}<BR>print "After accept\n";<BR> /* Send instructions.
*/<BR> $msg = "\nWelcome to the PHP Test Server. \n"
.<BR> "To quit, type 'quit'. To shut
down the server type 'shutdown'.\n";<BR>
socket_write($msgsock, $msg, strlen($msg));<BR>print "Above inner
loop\n";<BR> do
{<BR> if (FALSE === ($buf =
socket_read ($msgsock, 2048, PHP_NORMAL_READ)))
{<BR> echo
"socket_read() failed: reason: " . socket_strerror ($ret) .
"\n";<BR>
break 2;<BR>
}<BR> if (!$buf = trim ($buf))
{<BR>
continue;<BR>
}<BR> if ($buf == 'quit')
{<BR>
break;<BR>
}<BR> if ($buf == 'shutdown')
{<BR>
socket_close
($msgsock);<BR>
break 2;<BR>
}<BR> $talkback = "PHP: You said
'$buf'.\n";<BR> socket_write
($msgsock, $talkback, strlen
($talkback));<BR> echo
"$buf\n";<BR> } while (true);<BR>
socket_close ($msgsock);<BR>} while (true);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>socket_close
($sock);<BR>?><BR></FONT></DIV></BODY></HTML>