websockethttp
1.0.2 • Public • Published
websockethttp
npm install websockethttp
import client from 'websockethttp/client/index'
if (window) {
window.$wsh = $wsh
}
import 'websockethttp/client/index'
window.$wsh.openConnection('ws://', null)
// 打开与服务器的连接
client.openConnection('ws://127.0.0.1:8080/websocket/http', () => {
console.log('连接成功')
// 送消息到服务器的 chat 处理器 下的 Room 方法 (服务器如果没有注册这个处理器则消息服务器不会处理)
client.sendTextMessage("Chat", "Room", "你好服务器", (response) => {
console.log("发送结果与服务器的返回结果", response)
})
// 客户端注册一个处理器,等待服务端的请求 名称是 Chat 路径是 Room
client.registerRequestHandlerFunction("Chat", "Room", (request, response) => {
console.log('服务器的数据', request)
// 响应结果给服务器
response.code = 0
response.msg = 'ok'
response.body = '消息收到'
})
})
Package Sidebar
Install
Weekly Downloads