The WebSocket
is working perfectly in localhost (tomcat) . but when i host (Openshift - tomcat) it immediately disconnects and not firing the onMessage
method. I've checked the header and the status code is Status Code:101 Switching Protocols
.
Here is my socket.
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
@ServerEndpoint("/TestSocket")
public class TestSocket {
@OnOpen
public void onOpen(Session session) {
try {
session.getBasicRemote().sendText("Connected");
} catch (IOException e) {
e.printStackTrace();
}
}
@OnMessage
public void onMessage(Session session, String message) {
System.out.println("New message : " + message);
try {
session.getBasicRemote().sendText("Message received -> :" + message);
} catch (IOException e) {
e.printStackTrace();
}
}
@OnClose
public void onClose() {
System.out.println("Closed");
}
}
Here is the live socket ws://shifar-shifz.rhcloud.com:8000/MyTestProject/testWebSocket. I can't figure out what the problem is. Please help me.
EDIT
I am using the Tomcat 7 (JBoss EWS 2.0) cartridge. The project was deployed through a WAR
file.