socket.io-client 后台消息包含中文连接断开,请问有人遇到过吗

在实际项目中是第一次收到包含中文消息时连接中断,重连后正常,为了提问我把相关代码提取出来发现前端一收到含中文消息就不断报错重连了

server


import 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');

client


import 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)

});

此时是英文消息是正常的

https://img.mukewang.com/5cad5f660001f6f003150122.jpg

https://img4.mukewang.com/5cad5f670001aac904540114.jpg

可是一旦把服务器的

client.send({message: 'success'})

替换成包含中文的

client.send({message: '你好'})

立刻就崩溃了,前端不断的报错重连
https://img4.mukewang.com/5cad5f700001e09105440213.jpg

https://img2.mukewang.com/5cad5f710001b59403400272.jpg

socket.io socket.io-client
都已升级到 2.1.1
有大神知道什么原因吗


素胚勾勒不出你
浏览 1233回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript