Reputation: 449
I am using ec2, spring websocket using socksJS is working fine in local. I have already tried below things. 1. I dont have any load balancer which is blocking TCP. Request is directly going to ec2 server 2. Use true IP in place of ec2 server name.
while server its giving following issue in chrome console, there is no error in application server logs
WebSocket connection to 'ws://ec2-XX-X-XXX-XXX.compute-1.amazonaws.com/ws/963/kaidmvd9/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
Javascript
app.service('SocketService', function(httpService,$rootScope,SoundService) {
this.registerMe = function(callback){
$rootScope.socket = new SockJS("/ws");
$rootScope.stompClient = Stomp.over($rootScope.socket);
$rootScope.stompClient.connect('guest', 'guest', function(frame1) {
$rootScope.stompClient.subscribe('/user/'+$rootScope.loggedInUser.username+'/reply', function(frame2) {
var msg = JSON.parse(frame2.body);
console.log(msg);
});
},
function(error) {
console.log(error.headers.message);
}
);});
Spring xml
<websocket:message-broker application-destination-prefix="/app" >
<websocket:stomp-endpoint path="/ws">
<websocket:sockjs />
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic,/user" />
</websocket:message-broker>
Upvotes: 0
Views: 2552
Reputation: 201
Came to this through your T-Hub post, don't have enough reputation to add a comment else would have done that. Here's what you could try; use your EC2's private ip (find using ifconfig
) to host the WebSocket endpoint.
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/ws">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:stomp-broker-relay prefix="/topic,/user"
relay-host="your-ec2-private-ip-addr" relay-port="80" heartbeat-send-interval="20000" heartbeat-receive-interval="20000"/>
</websocket:message-broker>
Got help from: Java Spring STOMP: Set broker IP
Upvotes: 0