loopX2
loopX2

Reputation: 21

Jetty Websocket - sendString() triggers onClose (Error 1006 - Websocket Read EOF)

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);
}

Upvotes: 1

Views: 2826

Answers (2)

Astaroth
Astaroth

Reputation: 1

Just don't use port 8080. If you use, for example, 8081 this error does not appear.

Upvotes: 0

loopX2
loopX2

Reputation: 21

Ok, after hours of reading and searching I finaly found my mistake.

I am using Windows with Kaspersky preinstalled on my workdesk, my workmate using Linux without antivirus. In his Browser everything works fine, in my one connection is closed immediatly when try to receive a message.

It's my antivirus/firewall which is blocking http-websockets.

Solution: I am now ussing https-websockets with "wss://myIP:8443/mySite" and its working fine. A good tutorial is also this site here

Upvotes: 1

Related Questions