0
I received the exception "Chat socket closed unexpectedly
" in this javascript script:
const chatSocket = new WebSocket(
'ws://'
+ window.location.host
+ '/ws/chat/'
+ roomName
+ '/'
);
chatSocket.onmessage = function(e) {
const data = JSON.parse(e.data);
document.querySelector('#chat-log').value += (data.message + '\n');
};
chatSocket.onclose = function(e) {
console.error('Chat socket closed unexpectedly');
};
What’s the problem here ?? I can’t solve it
The answer to your question is in itself, chatSocket is closing, so you are getting the error, since it was the output that you put to print. Try to print the event itself, and use the browser’s Debugger to help you understand the code itself :D
– Murilo Melo
as it implemeted the
chatSocket.onclose
, implement thechatSocket.onopen
to see if you connected correctly and see if there are errors– Ricardo Pontual
Thank you I’ll do it
– bbbs personal area