我想尝试将我的应用程序连接到我们的后端以进行实时更新,但是我遇到这样的服务器错误。如果我添加本地服务器url或实时运行,它仍然是相同的错误。如何使用用于聊天消息传递应用程序的socket.io将我的应用程序连接到服务器。
componentDidMount(){
var YOURURL = "https://node.whizbite.com";
const socket = io(YOURURL);
console.log('socket',socket);
socket.on('connect', () => {
console.log("socket connected")
socket.emit('YOUR EVENT TO SERVER', {})
socket.on('EVENT YOU WANNA LISTEN', (r) => {
})
})
socket.on('connect_error', (err) => {
console.log("connection error",err)
})
socket.on('disconnect', () => {
console.log("Disconnected Socket!")
})
}
它给了我这种错误.....
Error: server error
at Socket.onPacket (socket.js:455)
at XHR.<anonymous> (socket.js:278)
at XHR.Emitter.emit (index.js:133)
at XHR.Transport.onPacket (transport.js:149)
at callback (polling.js:144)
at Object.exports.decodePayload (browser.js:384)
at XHR.Polling.onData (polling.js:148)
at Request.<anonymous> (polling-xhr.js:128)
at Request.Emitter.emit (index.js:133)
at Request.onData (polling-xhr.js:302)