博客
关于我
socket.io
阅读量:527 次
发布时间:2019-03-08

本文共 806 字,大约阅读时间需要 2 分钟。

const Koa = require("koa");const Router = require("koa-router");const static = require("koa-static");let app = new Koa();let router = new Router();app.use(static(__dirname+"/static"));router.get("/text",ctx=>{       ctx.body = "hello";});const server = require("http").createServer(app.callback());const io = require("socket.io")(server);//socket: 当建立连接后,传入回调函数中的参数//         它代表当前连接者!!io.on("connection",(socket)=>{       console.log("有连接");    let obj = {           name:"隔壁老王的快乐生活",        age:20    }    //传递数据    // setInterval(()=>{           // socket.emit("getData",obj);    // },1000);        socket.on("addData",(data)=>{           console.log(data);        socket.emit("getData",data);    });});// console.log(__dirname);// console.count(__filename);app.use(router.routes());server.listen(8989);

转载地址:http://gawiz.baihongyu.com/

你可能感兴趣的文章
MySQL分层架构与运行机制详解
查看>>
mysql大批量删除(修改)The total number of locks exceeds the lock table size 错误的解决办法
查看>>
mysql存储登录_php调用mysql存储过程会员登录验证实例分析
查看>>
Mysql工作笔记006---Mysql服务器磁盘爆满了_java.sql.SQLException: Error writing file ‘tmp/MYfXO41p‘
查看>>
MYSQL数据库下载安装(Windows版本)
查看>>
MySQL数据库与Informix:能否创建同名表?
查看>>
MySQL数据库操作
查看>>
MYSQL数据库简单的状态检查(show processlist)
查看>>
mysql数据恢复
查看>>
MySQL数据读写分离(MaxScale)上干货!!!
查看>>
Mysql新建用户和数据库并授权
查看>>
MySQL日期时间函数大全
查看>>
MySQL更新锁(for update)摘要
查看>>
MySQL服务器安装(Linux)
查看>>
mysql服务器查询慢原因分析方法
查看>>
mysql服务无法启动的问题
查看>>
mysql权限
查看>>
mysql条件查询
查看>>
MySQL架构与SQL的执行流程_1
查看>>
MySQL架构与SQL的执行流程_2
查看>>