PHP Swoole 簡單聊天室

2022-09-09 05:09:06 字數 827 閱讀 2596

效果圖

傳送

開始聊天

php **

date_default_timezone_set('prc');

$users = array();

//建立websocket伺服器物件,監聽0.0.0.0:9502埠

$ws = new swoole_websocket_server("0.0.0.0", 9502);

$ws->set(array(

'worker_num' => 1,

));//監聽websocket連線開啟事件

$ws->on('open', function ($ws, $request) );

//監聽websocket訊息事件

$ws->on('message', function ($ws, $frame)

}else\n";

$msg = ''.$users[$frame->fd].'

('.date('h:i:s').'): '.$frame->data.'

'; $ws->push($fd,$msg);}}

});//監聽websocket連線關閉事件

$ws->on('close', function ($ws, $fd) is closed\n";

});$ws->start();

放開埠號,然後執行php  test.php   //執行自己的php

簡單聊天室

include include include include include include include include include include pthread t thread 2 void send msg void ip msg if connect sockfd,struct ...

Linux UDP簡單聊天室

伺服器端 include include include include include include include include int sockfd 0 建立結構體用來存放客戶端資訊 typedef struct node node t node t link head node t h ...

go 簡單聊天室

package main import fmt net strings time 建立使用者結構體型別 type cline struct var onlinemap map string cline 建立全域性 channel 傳遞使用者訊息 var message make chan strin...