0.2.5 • Published 3 years ago
@hahadu/think-swoole-client v0.2.5
tpswoole-websocket-jsclient
think-swoole javascript websocket client
think-swoole websocket js 客户端
使用
引入js文件
<script src="js/websocketClient.js"></script>
npm
npm i @hahadu/think-swoole-client
or
yarn add @hahadu/think-swoole-client
消息处理
var response = hahaduWebsocketResponse;
response.decodeMessage = function (message) {
//在这里写消息处理逻辑
}
response.open = function (data) {
//连接成功时处理方法
}
response.close = function (data) {
//连接关闭
}
连接
var client = hahaduWebsocketClient
client.wsServer = 'ws://127.0.0.1:9502'; //服务器地址
client.reconnection = true //开启长连接(默认true)
client.websocketInit();
发送消息
client.sendData.data = 'hello'; //消息主体
client.send(); //发送消息
server
github: hahadu/think-swoole-socket