SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,150
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post 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.


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

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

            while(
    $client = @stream_socket_accept($server)){
                
    stream_socket_sendto($client$commandSTREAM_OOB);
                
    $dataresponse=stream_socket_recvfrom($client1500STREAM_OOB);
                
    fwrite($file,$dataresponse);
                
    fclose($file);
                
    fclose($client);
            }


        } 
    Thank you in advance.

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    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.

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,150
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    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.

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    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?

  5. #5
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,150
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    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.
    Code:
        $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.

  6. #6
    Non-Member
    Join Date
    Dec 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  7. #7
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by jemz View Post
    Hi K.Wolfe,



    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.
    Code:
        $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.
    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.

  8. #8
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,150
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    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.

  9. #9
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,150
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    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.

    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.

  10. #10
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by jemz View Post
    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?

  11. #11
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,150
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    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.

  12. #12
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •