Connecting websocket to local application through the application endpoint

The name of the picture


Connecting websocket to local application through the application endpoint



I'm trying to create a websocket in java that listens to a local application on the endpoint f.ex. "wss://localhost.localapp.com:8080/".



The application do send through that websocket information about what is happening.



I do have a HTML file and a JavaScript file.



In javascript it is really easy to create the connection with a websocket and get messages from the application.



But in java, I don't get anything through the same websocket. I wonder is there anything I'm missing?



The java file isn't connected to my HTML file in anyway. Do it have to be? I have seen several examples of where the endpoint is almost the same as the url of the webpage, but I only want to connect to the applications endpoint and get information from there.


@ClientEndpoint
public class ClientEndpoint {

private Logger logger = Logger.getLogger(getClass().getName());

public static void main(String args) {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
try {
container.connectToServer(Client.class, new URI("wss://localhost.localapp.com:8080/"));
} catch (DeploymentException | URISyntaxException | InterruptedException | IOException e) {
System.out.println("Connection error occured!: " + e);
}
}

@OnOpen
public void onOpen(Session session) {
this.logger.info("New websocket session opened: " + session.getId());
}

@OnClose
public void onClose(Session session) {
this.logger.info("Websoket session closed: " + session.getId());
}

@OnMessage
public void onMessage(Session session, String message) throws IOException, EncodeException {
this.logger.info("Message recieved: " + message);
}

@OnError
public void error(Session session, Throwable t) {
t.printStackTrace();
}
}



What else must be done to get the connection to the local application through the websocket?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP