Need help for the response

I need some help please, I am trying sending command to my device via stream_socket,but the problem is there is no response from the device.


   $file = fopen('response.log','a');
    $server = stream_socket_server('tcp://'.$serverip.':'.$port, $errno, $errormessage);

    if(!$server) {
        echo "$errormessage($errno)\\r\
";
    }
    else{

        while($client = @stream_socket_accept($server)){
            stream_socket_sendto($client, $command, STREAM_OOB);
            $dataresponse=stream_socket_recvfrom($client, 1500, STREAM_OOB);
            fwrite($file,$dataresponse);
            fclose($file);
            fclose($client);
        }


    }



Thank you in advance.

You said you tried to telnet in and ‘it shows the command when i press enter’? What exactly do you mean by this?

I’m going to stick with my original suggestion of sticking with testing with telnet until you get some actual results. There’s no point in trying to write PHP if you cant get connectivity through telnet or similar.

HI K.Wolfe,

Thank you for the reply…,The device is sending data now to our server and my socket script works fine and i can save the data to the text file,but my only problem is that if i will send a command to the device,the device won’t response with the command that i send,it’s always through data to our server which is not needed to me…

Thank you in advance.

Alright, I’m not sure I’m there yet with your description. Are you trying to send a command on the same pipe that is receiving the data? Have you successfully tested sending a command to the device under any circumstance?

Hi K.Wolfe,

Are you trying to send a command on the same pipe that is receiving the data?

No, Okay here is the scenario,I have also running stream_socket script which is the one that receives the data (similar code above),

like this.


    $file = fopen('receivedata.log','a');
    $server = stream_socket_server('tcp://'.$ipserver.':'.$port, $errno, $errorMessage);

    if(!$server) {
        echo "Problem on socekt";
    }
    else{

        while($client = @stream_socket_accept($server,$timeout)) {
               stream_copy_to_stream($client, $file);
               fclose($file);
               fclose($client);


        }

    }

If i will send command i will just run the other script that will send command to the device.

hey all,

I am also same facing the same problem, I tried what all suggestion you have given above but its still not working. Please help to sort this problem

Thanks in advance

Did sending the command through telnet work? If all your looking to do is record the response from a command being sent, you can pipe telnet into a log file.

Again, please test in telnet. There’s no point in coding until you’ve tested successfully there.

Hello K.Wolfe,Thank you for the reply…

do you want me to connect my device to my PC and then issue telnet command?.our device is place in other station.it’s far with me.

Hi K.Wolfe,

It’s working now i get the response now from the device i just figure it out that my command i send is wrong…I have another problem.if there is already running socket connection i could not run this command script…can you help me please how can i achieve if there is running connection i can run this script command.

Thank you in advance.

Well, once again I’m going to point you to use telnet for your testing. Fire up two terminals, trying connecting in with both using telnet, whats the result?

Hi K.Wolfe,

I run the script, but still it cannot connect if there is already running stream_socket script,I need to turn of first the first one,then run this script…

I don’t know why it could not connect.

Thank you in advance.

So that just sounds like the device is set up to only accept on socket connection. What was the result of the telnet test I wanted you to do?

I can’t stress enough here how you should not be using anything other than telnet (not PHP) to test the devices behavior.