in the actual project, this is the first time that the connection is broken when receiving a message containing Chinese, and it is normal after reconnection. In order to ask a question, I extracted the relevant code and found that the front end kept reporting errors as soon as it received the message in Chinese.
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)
});
now the English message is normal
][2]][1]
socket.io
socket.io-client
have all been upgraded to 2.1.1
does any god know why