在实际项目中是第一次收到包含中文消息时连接中断,重连后正常,为了提问我把相关代码提取出来发现前端一收到含中文消息就不断报错重连了serverimport http from 'http';import socket from 'socket.io';const server = http.createServer();const io = socket(server);io.on('connection', (client) => { console.log('SOCKET->connection:' + client.id); client.on('message', async function (message) { console.log(message); client.send({message: 'success'}) }); client.on('disconnect', async function () { console.log('SOCKET->disconnect:' + client.id); });});server.listen(3001);console.log('server running http://localhost:3001');clientimport io from 'socket.io-client';const socket = io('ws://localhost:3001');socket.on('connect', () => { console.log('connect'); socket.send({message: 'hello'})});socket.on('disconnect', () => { console.log('disconnect')});socket.on('error', err => { console.log(err)});socket.on('message', res => { console.log(res)});此时是英文消息是正常的可是一旦把服务器的client.send({message: 'success'})替换成包含中文的client.send({message: '你好'})立刻就崩溃了,前端不断的报错重连socket.io socket.io-client都已升级到 2.1.1有大神知道什么原因吗
添加回答
举报
0/150
提交
取消