Var time=null;
If (window. WebSocket) {
The socket=new WebSocket (" ws://localhost: 8001/ws ");
//messages are received
Socket. The onmessage=function (event) {
Let ta=document. GetElementById (" the responseText ");
Ta. Value=https://bbs.csdn.net/topics/ta.value + "\ n" + event. The data;
}
//connection open
Socket. Onopen=function (event) {
The console. The info (" connection open ");
Let ta=document. GetElementById (" the responseText ");
Ta. Value="https://bbs.csdn.net/topics/connection open";
Time=setTimeout (function () {
Window. The location. Reload ();
}, 1000);
}
//disconnects
Socket. Onclose=function (event) {
The console. The info (" connection closed ");
Let ta=document. GetElementById (" the responseText ");
Ta. Value=https://bbs.csdn.net/topics/ta.value + "\ n" + "connection closed;
}
} else {
Alert (" browser does not support WebSocket ");
}
The function the send (the message) {
if (! Window. The WebSocket) {
return;
}
If (socket. The readyState==WebSocket. OPEN) {
Socket. The send (message);
} else {
Alert (" connection has not been open ");
}
}
The back-end is written using netty + websocket, front is common js, occasionally connected not problems but also have no specific error message
CodePudding user response:
The problem, then solved?CodePudding user response:
Now solved yet