GithubHelp home page GithubHelp logo

guoyu07 / php-ws Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huangnie/php-ws

0.0 0.0 0.0 184 KB

基于Websocket 协议,PHP类库 和 javascript类库 , 实现事件+回调函数的架构开发,以一个简单聊天室实例介绍其使用方法

PHP 58.77% JavaScript 31.25% CSS 6.01% HTML 3.96%

php-ws's Introduction

php-ws

这说明以前发布在 http://www.oschina.net/p/php-ws, 今天才意识到这里太空白了,就弄了过来 实现基于Websocket 协议的 PHP类库 和 javascript类库 , 实现事件+回调函数的架构开发 ,以一个简单聊天室实例介绍其使用方法: 不同浏览器,不同电脑,不同地域, 实时通讯。实现的详细 请研究源码。

/服务端*/

/**

  • 实例化 */ $io = new SocketIO('127.0.0.1',8000);

/**

  • 监听连接 */ $io->on('connect',function($ws,$uid){ $msg = "任意数据类型,结构需要和前端协议,便于通信"; $ws->broadcast(evet, $msg); //$ws->emit(evet, $uid, $msg); });

/**

  • 任意事件,与前端协议好,// evet 由开发者定义 */ $io->on('event',function($ws,$uid,$msg){ $msg = "任意数据类型,结构需要和前端协议,便于通信"; $ws->broadcast(evet, $msg); });

/*

  • 关闭 */ $io->on('close',function($ws,$uid,$err){ // evet 由开发者定义 $msg = "任意数据类型,结构需要和前端协议,便于通信"; $ws->broadcast('close', $msg); });

/**

  • 启动 */ $io->run();

/*** 客户端 ***/

var io = new SocketIO('127.0.0.1',8000); io.on('connect',function(){ console.log('open'); // 发出请求, event 由开发者定义 io.emit(event, user, function(ok){ if(ok){
}else{
} }); // 收到消息, event 由开发者定义 io.on(event, function(msg){
console.log(msg); }); //关闭事件 io.on('close', function(){ }); });

php-ws's People

Contributors

huangnie avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.