I'm building my java web application on my home server.
My home server is using apache2 as the web-server and tomcat(9.0.5) as the java-container, along with mysql database, all on Ubuntu OS 16.04 LTS.
I try to build the .war file then deploy through tomcat , everything worked well, even the MySQL database connection , then i realize that my Websocket is not working.
There is no initial message sent from server and client cannot send message to server as well. There is no error in the browser console showing that there is a websocket connection error.
The odd is, my web app work well when deployed by netbeans on my localhost, can someone tells me what have i missed.
Although i think the problem is how i deploy the app, but for more info, this is the snapshot of my code for websocket on both client and server.
Client (using javascript):
function onMessage(e) {...} //some implementations
var socket = null;
window.onload = function() {
var uname = ...;
socket = new WebSocket("ws://" + window.location.host + getPageContextPath() + "/actions/"+uname+"/review/"+bookID);
socket.onmessage = onMessage;
};
Server (using java annotation):
@ApplicationScoped
@ServerEndpoint(value = "/actions/{uname}/{page}/{id}")
public class EndpointServer {
@OnOpen
public void onOpen(Session session, @PathParam("uname") String uname,
@PathParam("page") String page, @PathParam("id") String id) {
//do something when a client view the page
...
}