Example #1
0
        echo "[INFO] : message received, " . $message;
        $this->broadcast($message);
    }
    protected function connected($user)
    {
        $response = array();
        $response["status"] = "connected";
        $response["text"] = "환영합니다";
        $response["type"] = "system";
        //연결된 유저 추가
        array_push($this->CONNECTED_USR, $user);
        $this->send($user, json_encode($response));
    }
    protected function broadcast($message)
    {
        //접속한 모든 유저에게 메시지를 보내는 함수
        foreach ($this->CONNECTED_USR as $node) {
            $this->send($node, $message);
        }
    }
    protected function closed($user)
    {
        //todo : 연결이 끊긴 유저가 생기면 CONNECTED_USR 에서 삭제해야 한다
    }
}
$chat_server = new ChatServer("0.0.0.0", "9000");
try {
    $chat_server->run();
} catch (Exception $e) {
    $chat_server->stdout($e->getMessage());
}
Example #2
0
<?php

declare (ticks=1);
require dirname(__FILE__) . '/__settings__.php';
import('core.Log');
import('core.Request');
Log::disable_display();
import('Chat.ChatServer');
header('application/x-javascript');
$req = new Request();
$object_list = C(ChatMessage)->find_all(Q::gt('id', $req->inVars('since_id', 0)), Q::order('-id'));
if (count($object_list) > 0) {
    echo ChatServer::models_to_jsonp(array_reverse($object_list), $req->inVars('callback', 'callback'));
    exit;
}
$server = new ChatServer();
pcntl_signal(SIGTERM, array(&$server, 'models_json'));
pcntl_signal(SIGHUP, array(&$server, 'models_json'));
pcntl_signal(SIGUSR1, array(&$server, 'models_json'));
sleep(def('chat@timeout'));
Example #3
0
#!/usr/bin/env php
<?php 
define('zoop_dir', dirname(__FILE__) . '/../../framework');
define('app_dir', dirname(__FILE__));
include zoop_dir . '/Zoop.php';
Zoop::loadLib('Pherver');
$chatserver = new ChatServer();
$chatserver->run('127.0.0.1', 9050);
Example #4
0
 public static function __import__()
 {
     self::$pid = posix_getpid();
     self::touch_pid();
 }