0

I need to post some data to the listening serwer and get answear using sockets in php.

Putting work fine (receiver get what he needs), but when I try to get any serwer answear I just cant. It just goes over and over and over... looks like while never ends but why? (on the serwer side team check and say that responce is submitet to me).

I use Php but serwer is c++ (I heard this might be the problem)

The code:

ini_set('max_execution_time', 36000); // to test the shile for a longer time, but aparentry responce goes right away

$fp = fsockopen("192.168.x.x", 9999, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {

    echo "Connected<br />\n";

$out = chr(11)."MSH|....some fields there....|".chr(28).chr(13); //chr(x) are ruquired by serwer

if ( fputs($fp, $out, strlen($out)) )
{

    echo "<br />\nwriting message<br />\n";//if I eomment the while below this will show without problem

    while (!feof($fp)) {
       echo fgets($fp, 1024);
    }//just goes and goes... never finding end of file (I gues)
}

    fclose($fp);
}

I used 3 different ways in php to open socket and they all seem to have similar issue. How can I test what is going wrong?

1 Answer 1

1

I would try fwrite instead of fputs, but your code looks fine, you should describe what you use it for, which server and so on to get a bit documentation about it.

And choose TCP/UDP.

$fp = fsockopen('udp://192.168.X.X', '9999', $errno, $errstr, 10);
fwrite($fp, '\\xff\\xff\\xff\\xff\\'); 

And try this.

 do {
      $contents .= fgetc($fp);
      $socketstatus = socket_get_status($fp);    
    } while($socketstatus["unread_bytes"]); 

 echo $contents;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.