I have written a simple client-server app where the client uses WebSocket in Javascript and the server uses the Jetty library for WebSocket. This is the server code that handles messages from the client:
@OnWebSocketConnect
    public void onConnect(Session session) {
        System.out.println("Connected");
    }
    @OnWebSocketMessage
    public void onMessage(String message) {
        System.out.println(message);
    }
and this is the code of the client when sending messages:
function Search() {
"use strict";
sender = new WebSocket("ws://localhost:8080");
sender.send("Hello server");
sender.close();
}
So when I call the "Search" function the output of the server is this:
Which means line sender.send("Hello server"); was not executed.
But when I insert alert("connected"); after sender = new WebSocket("ws://localhost:8080"); this is the new output:
I have read the documentation about send() but it does not address this issue. Do you have any ideas why this happens?