Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSocket handshake: Unexpected response code: 404

Am writing my first websocket program and am getting "WebSocket handshake: Unexpected response code: 404", error while loading the webpage.

I am using JDK 1.7 and jboss 8 (wildfly8.0).

Could anyone please assist?

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

and head in html

<head> 
 <title></title>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <script src="websocket.js" type="text/javascript"></script> 
 <link rel="stylesheet" type="text/css" href="style.css"> 
</head>
like image 357
Saurabh Jhunjhunwala Avatar asked Apr 05 '15 09:04

Saurabh Jhunjhunwala


2 Answers

Thank you guys for your suggestion, I found the answer.

The code I copied is from http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html site.

The problem was the url as mentioned in the js file and the project name they are proposing is WebsocketHome. I had changed the project name to Websocket thus my url should be ws://localhost:8080/Websocket/actions.

Thanks for your support.

like image 87
Saurabh Jhunjhunwala Avatar answered Oct 05 '22 22:10

Saurabh Jhunjhunwala


Actually, the problem here is case-sensitivity in the URLs. You did not need to change the project name. Just changing the Websocket URL in JavaScript file to

ws://localhost:8080/WebSocketHome/actions 

(with capital S, as in the project name) would have solved the problem. In your case, changing both of them removed the case inconsistency, so it worked.

like image 34
scaleSpace Avatar answered Oct 05 '22 23:10

scaleSpace