eclipse-ee4j / eclipse-ee4j/tyrus

Websocket close with 1006 unless connect by localhost

Open
#614 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
128
Forks
49
PR merge metrics
No merged PRs in 30d

Description

I am trying to use websocket.

However I can only connect to localhost. Any remote client connecting will result in code 1006 after socket.getBasicRemote().sendText();

My server side is using java. Client side is using javascript. Java is listening on 8080 with glassfish 4.11 (Tried tomcat8 as well). I tested using 2 client and both are able to connect to 8080 with HTTP.

**Server side:**

@ServerEndpoint("/test")
public class Test {
final static Logger logger = Logger.getLogger(HelloWorld.class);
@OnMessage
public void onMessage(Session session, String message) {
try {
logger.info(message);
session.getBasicRemote().sendText(message);
} catch (IOException ex) {
}
}
}

**Client Side:**



TODO supply a title





$(document).ready(function(){
var uri = URI.parse(window.location.href);
var socket = new WebSocket("ws://"+uri.hostname+":"+uri.port+"/WebSocketServer/test");
socket.onopen = function(evt){
console.log(evt);
}
socket.onmessage = function(evt){
console.log(evt.data);
}
socket.onclose = function(evt){
console.log(evt);
}
$("#click").click(function(){
socket.send("asdf");
})
})



click

When connecting to localhost, the server is able to send message to client

This is the dump in javascript console (localhost)

test.html:19 Event {isTrusted: true, type: "open", target: WebSocket, currentTarget: WebSocket, eventPhase: 2…}bubbles: falsecancelBubble: falsecancelable: falsecomposed: falsecurrentTarget: WebSocketdefaultPrevented: falseeventPhase: 0isTrusted: truepath: Array(0)returnValue: truesrcElement: WebSockettarget: WebSockettimeStamp: 192.78type: "open"__proto__: Event
test.html:23 asdf

This is the dump when connectin using remote client

test.html:19 Event {isTrusted: true, type: "open", target: WebSocket, currentTarget: WebSocket, eventPhase: 2…}
test.html:26 CloseEvent {wasClean: false, code: 1006, reason: "", type: "close", target: WebSocket…}

Also I can confirm that the server did reply the client by inspecting the packet. The following is a packet captured in another endpoint similar to this

Frame 65: 113 bytes on wire (904 bits), 113 bytes captured (904 bits) on interface 0
Ethernet II, Src: Sonicwal_e1:87:e0 (00:17:c5:e1:87:e0), Dst: Micro-St_ae:a2:00 (44:8a:5b:ae:a2:00)
Internet Protocol Version 4, Src: 192.168.1.33, Dst: 192.168.0.103
Transmission Control Protocol, Src Port: 8080 (8080), Dst Port: 33962 (33962), Seq: 304, Ack: 557, Len: 59
WebSocket
1... .... = Fin: True
.000 .... = Reserved: 0x00
.... 0001 = Opcode: Text (1)
0... .... = Mask: False
.011 1001 = Payload length: 57
Payload
Line-based text data
{"type":"NORMAL","payload":"sdfasdf joined the channel."}

Please asist

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.