I am building a simple websocket connection
I tried it with javascript for testing:
// Create WebSocket connection.
const socket = new WebSocket(
`wss://public-api.birdeye.so/socket?x-api-key=` + apiKey,
'echo-protocol'
)
// Connection opened
socket.addEventListener('open', (event) => {
console.log('[socket] Connected')
})
the js code works just fine, I get messages from the websocket
but in Java the same code, doesnt work at all
import java.net.URI;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
public class WebSocketTest {
public static void main(String[] args) {
WebSocketTest ws = new WebSocketTest();
ws.testWebsocket();
}
private void testWebsocket() {
String apiKey = MYAPIKEY;
String wssURL = "wss://public-api.birdeye.so/socket?x-api-key=" + apiKey;
WebSocketClient client = new WebSocketClient(URI.create(wssURL)) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
System.out.println("WebSocket Client Connected");
}
@Override
public void onMessage(String s) {
System.out.println("Received: '" + s + "'");
}
@Override
public void onClose(int i, String s, boolean b) {
System.out.println("Connection Closed " + s);
// OUTPUT: Connection Closed Invalid status code received: 500 Status line: HTTP/1.1 500 Internal Server Error
}
@Override
public void onError(Exception e) {
System.out.println("Connection Error: " + e.getMessage());
}
};
client.connect();
}
}
I get: Connection Closed Invalid status code received: 500 Status line: HTTP/1.1 500 Internal Server Error
I just cant get a websocket connection in Java
I tried different libraries, Chat-GPT for help, same error