2
votes

I am using Openfire(V 3.9.1) server to send notification from PHP to Android. I am receiving message in Android properly. But I am unable to receive and display reply message back to PHP.

  • I am using XMPPHP library to send notification message from PHP to openfire server.
  • I'm using smack library. Android-to-android is working perfectly.

How do I receive/display messages on browser. Should I use a different library? enter image description here

2
You will need to provide more information. Are you able to connect to the server? What exactly isn't working?Robin
can you share the code which you are using to send message from php to openfire???Hirdesh Vishwdewa

2 Answers

2
votes

I have made the code for sending message to openfire but i dont know how to retrive the message.

i feel this can help you out.

include './XMPPHP/XMPP_Old.php';
    $host = 'XXX.XXX.XXX.XXX'; // ex.192.168.2.1  
    $port = '5222'; // its defauls xmpp port 
    $username = 'prashant76@mypc'; // ex vivek@host 
    $pass = '########';
    $conn = new XMPPHP_XMPP($host , $port, $username, $pass, 'localhost','localhost', $printlog=false, 

$loglevel=XMPPHP_Log::LEVEL_INFO);  
    try {
       $conn->useEncryption(FALSE);
        //$conn->useSSL(FALSE);
        $str='hello this is messge form php';
        $conn->connect();
        $conn->processUntil('session_start');
        $conn->presence();
        $str= $conn->message('XXXX@XXXXXXXXX', $str); // for sending the message.
        $conn->disconnect(); 
    } catch(XMPPHP_Exception $e) {
             die($e->getMessage()); 
    } 
0
votes

You can configure openfire to save messages to mysql database. Then you can either use 'ajax long polling' method or websockets to fetch new records from database and display them on browser. Refer the below links for more details.

Websockets : http://www.html5rocks.com/en/tutorials/websockets/basics/

Ajax long polling PHP : How do I implement basic "Long Polling"?