Every time my WebSocket sends a message to my client, the client calls the onClose-function for the connection and does not receive the message.
Error is 1006 - Websocket Read EOF
I am aware of this answer getting the reason why websockets closed , so error is locally by browser, but I am using Firefox(newest) and html and javascript code is nothing special.
Until server calls session.getRemote().sendString or sendStringByFuture client seems to be connected. When sendString(message) is called, ws.onclose is triggered always!
The Server side:
My Websocket.war runs on a jetty-server with module deploy, http, jsp, client and websocket and in my opinion connection is successful etablished. (See log)
I took the official jetty-websocket example. I deleted Main.java, because I map the websocket-server using import javax.servlet.annotation.WebServlet;
import javax.servlet.annotation.WebServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
@SuppressWarnings("serial")
@WebServlet(value="/start", asyncSupported = true)
public class WebServerTest extends WebSocketServlet{
@Override
public void configure(WebSocketServletFactory factory) {
factory.register(WebSocketTest.class);
}
}
Jetty-Serverlog:
WebSocket Connect: WebSocketSession[websocket=JettyAnnotatedEventDriver[org.el.WebSocketTest@e0bb5f],behavior=SERVER,connection=WebSocketServerConnection@4a0644db[ios=IOState@3986db[CONNECTED,!in,out],f=Flusher[queueSize=0,aggregateSize=0,failure=null],g=Generator[SERVER,validating,+rsv1],p=Parser@11f79d8[ExtensionStack,s=START,c=0,len=0,f=null]]<-SocketChannelEndPoint@694908{/myIP:somePort<->/myIP:8080,OPEN,fill=-,flush=-,to=0/300000}{io=0/0,kio=0,kro=1}->WebSocketServerConnection@4a0644db[ios=IOState@3986db[CONNECTED,!in,out],f=Flusher[queueSize=0,aggregateSize=0,failure=null],g=Generator[SERVER,validating,+rsv1],p=Parser@11f79d8[ExtensionStack,s=START,c=0,len=0,f=null]],remote=WebSocketRemoteEndpoint@1a29617[batching=true],incoming=JettyAnnotatedEventDriver[org.el.WebSocketTest@e0bb5f],outgoing=ExtensionStack[queueSize=0,extensions=[permessage-deflate],incoming=org.eclipse.jetty.websocket.common.extensions.compress.PerMessageDeflateExtension,outgoing=org.eclipse.jetty.websocket.common.extensions.compress.PerMessageDeflateExtension]]
When i try to send a answer from Server to client
Echoing back text message [start]
INFO:oe.WebSocketTest:qtp8420901-11: WebSocket Close: 1006 - WebSocket Read EOF
The Client side:
Firefox can etablish a connection to "ws://myIP:8080/Websocket/start" and receives a ws.onopen.
example.js
try {
var ws = new WebSocket("ws://myIP:8080/Websocket/start");
} catch(Exception){ altert("Help"); }
ws.onopen = function () {
appendLog("Connected to socket service!");
};
ws.onmessage = function (evt) {
appendLog(evt.data);
};
ws.onclose = function () {
appendLog("Disconnected from stock service!");
};
ws.onerror = function (err) {
console.log("ERROR!", err);
};
function appendLog(logText) {
var log = document.getElementById("log");
log.value = log.value + logText + "\n";
}
function sendToServer(msg) {
ws.send(msg);
}