workman发送即时消息

workerman下载地址:https://www.workerman.net/

workman发送即时消息_第1张图片-》workman发送即时消息_第2张图片

1,start.php  workerman服务器

2,song.html发送页面

3,wor.html接收页面

4,php  start.php  start   连接workerman服务

5,telnet 127.0.0.1 2345  测试是否连接成功

start.php :

uid = ++$global_uid;
}

//	当客户端发送消息过来时,转发给所有人
function handle_message($connection,$data){
    global $text_worker;
    foreach ($text_worker->connections as $conn){
        $conn->send("user[{$connection->uid}]	said:	'是的'");
    }
}

//	当客户端断开时,广播给所有客户端
function handle_close($connection){
    global $text_worker;
    foreach ($text_worker->connections as $conn){
        $conn->send("user[{$connection->uid}] logout");
    }
}

//	创建一个文本协议的Worker监听2347接口
$text_worker = new Worker('websocket://0.0.0.0:2345');

//	只启动1个进程,这样方便客户端之间传输数据
$text_worker->count = 1;

$text_worker->onConnect='handle_connection';
$text_worker->onMessage='handle_message';
$text_worker->onClose = 'handle_close';
Worker::runAll();


song.html :




    
    
    
    Document


您好:





wor.html : 




    
    
    
    Document


我很好:



通过start.php内IP地址连接

 

你可能感兴趣的:(workman发送即时消息)