2

Good Day,

I have a hardware device (an RN-XV WiFi chip) which has successfully connected to my server IP address through port 80. I am able to send junk data and it responds with a "server is unable to serve this request", meaning there is a connection.

Now, I need to talk to this device/send it data/strings. I know some basic PHP, but I have no idea how to approach this problem. My device is connected to the server but:

  1. To send data to it, I have to know the IP/Port of the device connected right? How do I find that out?

  2. If I am able to obtain this..is sending data a matter of opening a TCP connection via PHP and sending a string?

  3. Now that I am connected to the server, I am somehow able to send strings, but it returns with a server unable to serve this request. How do I actually send data to a particular PHP file to read?

Please Help! Thanks in advance!

3
  • What is intended use? It will help us visualize your problem. Commented Feb 12, 2013 at 3:34
  • just testing communication between a server and a device thats all. for my embedded systems project. Commented Feb 12, 2013 at 3:44
  • yeah, but are you trying to send a command to the wireless device or use the wireless device to command something else? What is its function? Commented Feb 12, 2013 at 3:49

1 Answer 1

1

you must write program for socket .see this page for php socket programming http://php.net/manual/en/book.sockets.php

with this function you can connect to every port , send data and get response with every format that you want .

sample:for connect to Device

<?php
    $fp = fsockopen("udp://127.0.0.1", 2000, $errno, $errstr);
    if (!$fp) {
        echo "ERROR: $errno - $errstr<br />\n";
    } else {
       fwrite($fp, "data for send");
       while ( !feof( $fp ) ) { 
          $ret .= fgets( $fp, 4096 ); 
       }
       echo $ret;
       fclose($fp);
    }
?>

more sample http://php.net/manual/en/function.fsockopen.php

Sign up to request clarification or add additional context in comments.

14 Comments

Okay please answer this. My device is connected to my server, and if I want to use socket programming TCP or UDP..i need the IP address of my device! How on earth do I find this out? I only have the IP address of the device connected to my wireless network. what is the address of my device on the server?!
@user1436508 when php and device is on one server for connect to device use 127.0.0.1 ip is for inside of server
localhost is point to your php server that you run php on it .you can use it for connect to anther device and service on php server .
ARGH! please my question is very simple. my device is now listening to any/all responses sent via UDP from my server from say port 2000. it is configured like that. the problem is..what address do i send the UDP data to in the php script!? I cant send it to localhost right? I need to send it to my device! What do i do?
@user1436508 I Put One Sample for it see.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.