ionic学习与开发

ionic3 连接socket

2018-05-14  本文已影响11人  亦久亦韭

1.安装socket

npm install socket.io

2.建立socekt provider

import * as io from 'socket.io-client';

3.provider的方法

connetct() {

if (Boolean(this.storage.get('token')) ==true) {

this.socket = io('http://xxx.xxxx.com:3001/?token=' +this.storage.get('token'));

  }

}

//发送信息

sendMessage(key, message) {

this.socket.emit(key, message);

}

//断掉链接

disconnet() {

this.socket.disconnect(true);

}
上一篇 下一篇

猜你喜欢

热点阅读