function iotoserver($messageArr)
 {
     if (defined('NODEJS_HOST') && trim(NODEJS_HOST)) {
         App::import('Vendor', 'ElephantIO', array('file' => 'ElephantIO' . DS . 'Client.php'));
         try {
             $elephant = new ElephantIOClient(NODEJS_HOST, 'socket.io', 1, false, false, true);
             $elephant->setHandshakeTimeout(1000);
             $elephant->init();
             $elephant->send(ElephantIOClient::TYPE_EVENT, null, null, json_encode(array('name' => 'iotoserver', 'args' => $messageArr)));
             $elephant->close();
         } catch (Exception $e) {
         }
     }
 }
Example #2
0
 /**
  * 等待通讯
  */
 public function wait()
 {
     $this->_client->keepAlive();
 }
Example #3
0
function iotoserver($messageArr)
{
    if (defined('NODEJS_HOST') && trim(NODEJS_HOST)) {
        try {
            $elephant = new ElephantIOClient(NODEJS_HOST, 'socket.io', 1, false, false, true);
            $elephant->setHandshakeTimeout(1000);
            $elephant->init();
            $elephant->send(ElephantIOClient::TYPE_EVENT, null, null, json_encode(array('name' => 'iotoserver', 'args' => $messageArr)));
            $elephant->close();
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
}
Example #4
0
<?php

require 'ElephantIOClient.class.php';
$elephant = new ElephantIOClient('http://127.0.0.1:8080');
$elephant->init();
$elephant->send(ElephantIOClient::TYPE_MESSAGE, null, null, 'Hello World!');
$elephant->keepAlive();
Example #5
0
 /**
  * 等待通讯
  */
 public function wait()
 {
     while (true) {
         if ($this->_client) {
             $this->_client->keepAlive();
         }
         if ($this->_autoReconnect === false) {
             break;
         } else {
             if ($this->_client) {
                 $this->_client->close();
                 $this->_client = null;
             }
             $this->_messageCallbacks = array();
             try {
                 $this->_client = new ElephantIOClient("http://" . $this->_server . ":" . $this->_port, "socket.io", 1, false, true, $this->_debug);
                 $this->init();
                 if ($this->_useSessionId) {
                     $this->connect_v2();
                 } else {
                     $this->connect();
                 }
             } catch (Exception $e) {
                 if ($this->_client) {
                     $this->_client->close();
                     $this->_client = null;
                 }
                 sleep(5);
             }
         }
     }
 }