1

当尝试将我的 react forntend 与 netty -websocket 示例连接时,我收到了来自 sock.io 客户端的此错误:

{ 
  message: 'server error', 
  name: 'Error' 
}

是的,不开玩笑。他们的前端在使用npx serve. 我正在使用sock.io-client version 4.1.2. 我试过更改连接网址,但它没有解决任何问题。

这是我的前端代码:

const url = `http://${socketUrl}/chat`;

export const initWebsocketConnection = () => {
   console.log(io)
   const socket = io('localhost:9092/chat');
   socket.on('connect', function () {
       console.log('<span class="connect-msg">The client has connected with the server.');
   });
   socket.on('chat', function (data) {
     console.log('Received message', data);
     console.log('<span class="username-msg">' + data.userName + ':</span> ' + data.message);
   });
   socket.on('disconnect', function () {
     console.log('<span class="disconnect-msg">The client has disconnected!</span>');
   });
   socket.on('reconnect_attempt', (attempts) => {
     console.log('Try to reconnect at ' + attempts + ' attempt(s).');
   });
   socket.on("connect_error", (reason) => {
     console.log(reason.message, reason.name, )
   });
}

Java 服务器不记录任何内容。我的浏览器中的堆栈跟踪是这样的:

    onPacket@http://localhost:3000/static/js/vendors~main.chunk.js:19409:23
./node_modules/component-emitter/index.js/Emitter.prototype.emit@http://localhost:3000/static/js/vendors~main.chunk.js:17691:20
onPacket@http://localhost:3000/static/js/vendors~main.chunk.js:19817:10
callback@http://localhost:3000/static/js/vendors~main.chunk.js:20563:12
onData@http://localhost:3000/static/js/vendors~main.chunk.js:20567:56
./node_modules/component-emitter/index.js/Emitter.prototype.emit@http://localhost:3000/static/js/vendors~main.chunk.js:17691:20
onData@http://localhost:3000/static/js/vendors~main.chunk.js:20338:10
onLoad@http://localhost:3000/static/js/vendors~main.chunk.js:20394:12
create/xhr.onreadystatechange@http://localhost:3000/static/js/vendors~main.chunk.js:20291:18
EventHandlerNonNull*create@http://localhost:3000/static/js/vendors~main.chunk.js:20287:9
Request@http://localhost:3000/static/js/vendors~main.chunk.js:20228:10
request@http://localhost:3000/static/js/vendors~main.chunk.js:20174:12
doPoll@http://localhost:3000/static/js/vendors~main.chunk.js:20204:22
poll@http://localhost:3000/static/js/vendors~main.chunk.js:20537:10
doOpen@http://localhost:3000/static/js/vendors~main.chunk.js:20484:10
open@http://localhost:3000/static/js/vendors~main.chunk.js:19751:12
open@http://localhost:3000/static/js/vendors~main.chunk.js:19226:15
Socket@http://localhost:3000/static/js/vendors~main.chunk.js:19163:10
./node_modules/engine.io-client/lib/index.js/module.exports@http://localhost:3000/static/js/vendors~main.chunk.js:19037:33
open@http://localhost:3000/static/js/vendors~main.chunk.js:75157:19
reconnect/timer<@http://localhost:3000/static/js/vendors~main.chunk.js:75426:14
setTimeout handler*reconnect@http://localhost:3000/static/js/vendors~main.chunk.js:75420:31
maybeReconnectOnOpen@http://localhost:3000/static/js/vendors~main.chunk.js:75141:12
open/errorSub<@http://localhost:3000/static/js/vendors~main.chunk.js:75178:14
./node_modules/component-emitter/index.js/Emitter.prototype.emit@http://localhost:3000/static/js/vendors~main.chunk.js:17691:20
onError@http://localhost:3000/static/js/vendors~main.chunk.js:19611:10
onPacket@http://localhost:3000/static/js/vendors~main.chunk.js:19411:16
./node_modules/component-emitter/index.js/Emitter.prototype.emit@http://localhost:3000/static/js/vendors~main.chunk.js:17691:20
onPacket@http://localhost:3000/static/js/vendors~main.chunk.js:19817:10
callback@http://localhost:3000/static/js/vendors~main.chunk.js:20563:12
onData@http://localhost:3000/static/js/vendors~main.chunk.js:20567:56
./node_modules/component-emitter/index.js/Emitter.prototype.emit@http://localhost:3000/static/js/vendors~main.chunk.js:17691:20
onData@http://localhost:3000/static/js/vendors~main.chunk.js:20338:10
onLoad@http://localhost:3000/static/js/vendors~main.chunk.js:20394:12
create/xhr.onreadystatechange@http://localhost:3000/static/js/vendors~main.chunk.js:20291:18
EventHandlerNonNull*create@http://localhost:3000/static/js/vendors~main.chunk.js:20287:9
Request@http://localhost:3000/static/js/vendors~main.chunk.js:20228:10
request@http://localhost:3000/static/js/vendors~main.chunk.js:20174:12
doPoll@http://localhost:3000/static/js/vendors~main.chunk.js:20204:22
poll@http://localhost:3000/static/js/vendors~main.chunk.js:20537:10
doOpen@http://localhost:3000/static/js/vendors~main.chunk.js:20484:10
open@http://localhost:3000/static/js/vendors~main.chunk.js:19751:12
open@http://localhost:3000/static/js/vendors~main.chunk.js:19226:15
Socket@http://localhost:3000/static/js/vendors~main.chunk.js:19163:10
./node_modules/engine.io-client/lib/index.js/module.exports@http://localhost:3000/static/js/vendors~main.chunk.js:19037:33
open@http://localhost:3000/static/js/vendors~main.chunk.js:75157:19
Manager@http://localhost:3000/static/js/vendors~main.chunk.js:75082:33
lookup@http://localhost:3000/static/js/vendors~main.chunk.js:74957:19
initWebsocketConnection@http://localhost:3000/static/js/main.chunk.js:2945:73
initializeApplication@http://localhost:3000/static/js/main.chunk.js:2199:92
initKeycloak/<@http://localhost:3000/static/js/main.chunk.js:2681:7
promise callback*initKeycloak@http://localhost:3000/static/js/main.chunk.js:2677:6
./src/index.js/<@http://localhost:3000/static/js/main.chunk.js:2235:62
./src/index.js@http://localhost:3000/static/js/main.chunk.js:2314:30
__webpack_require__@http://localhost:3000/static/js/bundle.js:852:31
fn@http://localhost:3000/static/js/bundle.js:151:20
1@http://localhost:3000/static/js/main.chunk.js:3424:18
__webpack_require__@http://localhost:3000/static/js/bundle.js:852:31
checkDeferredModules@http://localhost:3000/static/js/bundle.js:46:23
webpackJsonpCallback@http://localhost:3000/static/js/bundle.js:33:19
@http://localhost:3000/static/js/main.chunk.js:1:81
4

1 回答 1

0

由于 socket-io 服务器和客户端的版本而存在错误。2.2.0 版工作得很好。

Netty-Socketio 应该得到更新。版本 3.1.0 不适用于 Java 服务器,只有 2.2.0 可以。

于 2021-06-20T23:00:54.087 回答