<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< title > Title< / title >
< / head >
< body >
< button onclick = "sendHandler('zhangsan')" > 给zhangsan发送消息< / button >
< button onclick = "sendHandler('wangwu')" > 给wangwu发送消息< / button >
< script >
// const token = ""
// var ws = new WebSocket("ws://192.168.0.70:8801/ws/imserver?token=" + token)
var ws = new WebSocket("ws://192.168.0.70:8999/ws/imserver/lisi")
ws.open = function (msg) {
console.log("open:" + msg)
}
ws.onmessage = function (msg) {
console.log("message:" + msg)
}
function sendHandler(userid) {
var param = {}
param.sendUserId = 'lisi'
param.receiveUserId = userid
param.message = '来自 lisi 消息'
param.msgType = 2
param.uuid = new Date() * 1
ws.send(JSON.stringify(param))
}
< / script >
< / body >
< / body >
< / html >