I'm having trouble doing what ought to be a very simple thing and have searched and read everything I can find in the docs and this site to no avail.
I've written a TCP/IP java server application that takes basic text commands received on a socket and returns responses to the sender.
I've written a java client application that communicates to the server fine. This simple command/response protocol is well tested and works great. FYI, the server displays in a text window when a connection is accepted and the text of all incomming commands, as well as when a connection is broken (the server goes back to accept a new connection).
I am (excitedly) implementing a PHP client. By the way, PHP is awesome! I eventually will convert the server from Java to PHP.
The PHP client successfully opens a socket and the server indicates the connection has been established. Here is where the trouble starts.
The server never receives messages I send using either fputs or fwrite. I've even looped re-sending the message multiple times to no avail. There is no error. Rather, the send completes and the server never receives the message.
When the PHP client closes the socket, the server indicates this has happened and goes back to accept mode.
I must be missing somethig obvious here. Any help would be greatly appreciated. Thank you in advance.
Here is a code snippet:
function initialize()
{
$ret = "";
$fp = fsockopen ("localhost", 63792, $errno, $errstr, 30);
// My server indicates the socket is open
// at this point (for grins, I also did
// this successfully using 127.0.0.1)
if (!$fp)
return "$errstr ($errno)</br>";
// Turn off blocking...
socket_set_blocking ($fp, FALSE);
// A simple command recognized by
// My server...
$out = '/?trans/';
// I've sent this with and without
// the length parameter. I've also
// used fputs (that's how I originally
// did it, by the way)
fwrite ($fp, $out, strlen($out));
// My server never indicates the above
// message was received...
// A java client can send the exact same
// message and the server indicates that
// it has receive the message fine,
// by the way...
// Collect the response messages
while (!feof($fp))
{
// I've used varying lengths. Also,
// I've omitted the length paramter
$ret = $ret . fgets ($fp,128);
}
// Clean up...
fclose ($fp);
return $ret;
}