GithubHelp home page GithubHelp logo

wff650 / swoole.imsocket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xiaolingzi/swoole.imsocket

0.0 2.0 0.0 35 KB

swoole socket

License: GNU General Public License v3.0

PHP 96.87% Shell 0.16% HTML 2.97%

swoole.imsocket's Introduction

xiaolingzi Swool.IMSocket 基于swoole的聊天通讯socket

更多分享请访问 https://www.xxling.com  

运行

在安装好swoole和php之后,直接运行项目文件夹下的App.php文件

php /{实际目录}/application/Projects/IMSocket/App.php -i e

前台后台运行可以通过SwooleServer.php里面的配置项进行配置,还要注意将公共和项目下的config目录中的配置修改为自己的
swoole的相关文档请前往 http://www.swoole.com

消息格式  

客户端消息发送格式如下(注意要加上结束符#$#):
身份验证
{"infoType": 100001,"connectionType": 2,"data":{"token":"","userId":1}}#$#
实际应用中token改为实际验证的token

双人对话
{"infoType": 110001,"connectionType": 2,"data":{"userId":1,"toUserId":2,"messageContent":"user message","messageType":1}}#$#

群聊消息
{"infoType": 110002,"connectionType": 2,"data":{"userId":1,"clubId":1,"messageContent":"club message","messageType":1}}#$#

服务端返回消息格式:
双人对话
{"code":"N00000","message":"xxx","infoType":110001,"data":{"userId":1,"toUserId":2,"messageContent":"user message","messageType":1,"userName":"test1","avatar":""}}#$#

群聊
{"code":"N00000","message":"xxx","infoType":110002,"data":{"userId":1,"clubId":1,"messageContent":"club message","messageType":1,"userName":"test1","avatar":""}}#$#

消息主要使用json格式进行传输,传输的内容和格式大家可以自己定义,代码层面做相应修改就好,infoType的含义看项目下的 CommonDefine.php 文件,这里就不多说。  

测试

项目目录下有test1.html和test2.html两个文件,分别在两个浏览器中打开,就可以用来简单的测试收发数据了。

更详细说明请访问:https://www.xxling.com/blog/article/3106.aspx

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.