set(array('task_worker_num' => 1));$serv->on('Open', function ($server, $req) {static $isTask = false;echo "已连接上{$req->fd}\r\n";if(!$isTask){$task_id = $server->task('1');$isTask = true;}});
$serv->on('Message', function ($server, $frame) {echo "对方[{$frame->fd}]: " . $frame->data . "\r\n";}); $serv->on('Close', function ($server, $fd) {echo "connection close: " . $fd;});
$serv->on('Task', function ($serv, $task_id, $from_id, $data) {while($cdata = trim(fgets(STDIN))){$serv->finish($cdata);} }); $serv->on('Start', function ($serv) {}); $serv->on('Finish', function ($server, $task_id, $data) {// echo "AsyncTask[$task_id] Finish: $data".PHP_EOL;if($data!==''){foreach($server->connections as $fd){$server->push($fd, $data);} }});
$serv->start();
Testing websockets发送' +"对方:"+ event.data;
}
function onOpen(event) {
document.getElementById('messages').innerHTML
= 'Connection established';
}
function onError(event) {
alert(event.data);
// alert("error");
}
function start() {
var msg = document.getElementById('msg').value;
webSocket.send(msg);
document.getElementById('messages').innerHTML
+= '' +"我:"+ msg;
return false;
}" _ue_custom_node_="true">