How to establish a socket connection from iPhone to a Apache server and communicate via PHP?

Posted by candoyo on Stack Overflow See other posts from Stack Overflow or by candoyo
Published on 2010-05-23T17:53:30Z Indexed on 2010/05/23 18:00 UTC
Read the original article Hit count: 229

Filed under:
|
|
|
|

Hi, I am working on an iPhone game which is depended on a LAMP server. I want to create a "event" based system where the apache server sends an event to the iphone.

For this, I am thinking of using "CFStreamCreatePairWithSocketToHost" to connect to port 80 of the apache server.

I am able to successfully connect to the server and open a read and write stream via the iPhone, but I am not sure how to send data to the iphone using PHP running from the LAMP server to the iPhone.

I think I can use fsockopen in php to open a socket connection and write data to that socket. I tired running this code

    $fp = fsockopen("tcp://localhost", 80, $errno, $errstr); 
     if (!$fp) {
      echo "ERROR: $errno - $errstr<br />\n";
    } else {

echo"writing to socket
"; fwrite($fp, "wwqeqweqw eqwe qwe \n");

//echo fread($fp, 26);
fclose($fp);
echo "done";
   }

But, I dont see anything being read on the iphone.. Any idea what's going on, or how to accomplish this?

Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about iphone