First websocket program and am getting “WebSocket handshake: Unexpected response code: 404”, error while loading the webpage on resin server


#1
window.onload = init;
var socket = new WebSocket("ws://localhost:8080/WebsocketHome/actions"); 
socket.onmessage = onMessage; 

I have copied this code from http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html# and working fine with glassfish server but when i tried with Resin 4.0.47 got handshake error. Tried many basic websocket programs which runs on tomcat and glassfish but not with resin server.Is there any specific configuration for Resin server?


#2

Hey @mahesh. One thing I notice is that your websocket is trying to connect to the local host instead of the devices url. Can you try change ws://localhost:8080/WebsocketHome/actions to ws://<UUID>.resindevice.io:8080/WebsocketHome/actions replacing <UUID> with the RESIN_DEVICE_UUID. Also ensure that you have enabled your deviceURL, you can see the documentation on that here: https://docs.resin.io/management/devices/#enable-public-device-url


#3

@mahesh I would also recommend looking at this example websocket project https://github.com/resin-io-projects/resin-websocket