WebSocket some problems about java

i use java codeing websocket.
this is API docs:
https://binance-docs.github.io/apidocs/spot/cn/#websocket
for example ,i use java coding websocke,look this:
public static void main(String args) {
try {
// ApiConfig.apiUrl += “/ws”;
ApiConfig.apiUrl = “wss://stream.binance.com:9443/ws”;
MyWebSocketClient webSocketClient = new MyWebSocketClient(new URI(ApiConfig.apiUrl));
webSocketClient.connect();
// webSocketClient.addHeader();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
However, it throws some errors,
@Override
public void onClose(int i, String s, boolean b) {
System.out.println(“connect error” + i +"–"+ s +"–"+ b);

}

@Override
public void onError(Exception e) {
    System.out.println("connect exception" + e.getMessage());

}

connect exceptionOperation timed out (Connection timed out)
connect error-1–Operation timed out (Connection timed out)–false
so,i want to know what i should do to use websocket correctly about java

The url you are querying is incomplete. you need to specify the stream name you want to listen. For example if i want to listen to Trade Streams for BNBUSDT pair, i would establish a connection to
ApiConfig.apiUrl = “wss://stream.binance.com:9443/ws/bnbusdt@trade”;

now,i use okhttp of java to get thier.
this’s error:
the end ,you cloud send a heartbea here
Failed to connect to stream.binance.com/2001:0:0:0:0:0:caa0:80c3:9443

                @Override
                public void onMessage(WebSocket webSocket, String text) {
                    System.out.println("get message:" + text);
                }
                @Override
                public void onMessage(WebSocket webSocket, ByteString bytes) {
                    System.out.println("get message type is byte");
                }

                @Override
                public void onClosing(WebSocket webSocket, int code, String reason) {
                    System.out.println("connect closing");
                }
                @Override
                public void onClosed(WebSocket webSocket, int code, String reason) {
                    System.out.println("connect close");
                }

                @Override
                public void onFailure(WebSocket webSocket, Throwable t, Response response) {
                    System.out.println("the end ,you cloud send a heartbea here");
                    System.out.println(t.getMessage());
                }
            });

This is the top half:
OkHttpClient client = new OkHttpClient.Builder().retryOnConnectionFailure(true).build();
ApiConfig.apiUrl += “/ws/bnbusdt@trade”;
Request request = new Request.Builder().url(ApiConfig.apiUrl)
.addHeader(“X-MBX-APIKEY”,ApiConfig.ApiKey)
.build();
client.dispatcher().cancelAll();
client.newWebSocket(
request, new WebSocketListener() {

You dont need the API key as header for websocket connection. The correct url should be
ApiConfig.apiUrl = “wss://stream.binance.com:9443/ws/bnbusdt@trade”;

Were you trying to establish a connection from China?

yes,now the code is :
String msg = “{“method”:“SUBSCRIBE”,“params”:[”!miniTicker@arr@3000ms",“btcusdt@aggTrade”,“btcusdt@kline_1m”,“btcusdt@depth”],“id”:2}";

    OkHttpClient client = new OkHttpClient.Builder().retryOnConnectionFailure(true).build();
    ApiConfig.apiUrl += "/ws/bnbusdt@trade";

    Request request = new Request.Builder().url(ApiConfig.apiUrl).build();

    client.dispatcher().cancelAll();
    client.newWebSocket(
            request,
            new WebSocketListener() {
                @Override
                public void onOpen(WebSocket webSocket, Response response) {
                    System.out.println("connect open");
                }

                @Override
                public void onMessage(WebSocket webSocket, String text) {
                    System.out.println("get message:" + text);
                }

                @Override
                public void onMessage(WebSocket webSocket, ByteString bytes) {
                    System.out.println("get message type is byte");
                    System.out.println(bytes.toString());
                }

                @Override
                public void onClosing(WebSocket webSocket, int code, String reason) {
                    System.out.println("connect closing");
                }

                @Override
                public void onClosed(WebSocket webSocket, int code, String reason) {
                    System.out.println("connect close");
                }
                @Override
                public void onFailure(WebSocket webSocket, Throwable t, Response response) {
                    System.out.println("the end ,you cloud send a heartbea here");
                    System.out.println(t.getMessage());
                }
            });

and the code running, response is:
connect open
get message type is byte
[size=121 hex=1f8b0800000000000000558b390a80301444ef3275906c26269da29568e102b682b15270ebc4bbfb2ded66e6cdbb11e0711de314c050c00b236269ad74c2f184…]
get message type is byte
[size=121 hex=1f8b0800000000000000558bbb0e40401444ff65ea8decaecbdaed08955078245a8955917875e2df5da56e66ce9c1b1e0ed7314e1e02059c8a55a48dd1565999…]
get message type is byte
[size=121 hex=1f8b0800000000000000ab564a55b2522a294a4c4955d2517255b23234333435323737b234b434b0d0510a411531d6512a06aa77f2730a0d760901ea2801ca1b…]
So I do not understand,what the response is??
What should I do next
and thank you

thanks for you.
even though you withdraw,

Let’s try to use websocat to test the connection first. Launch your terminal, type
websocat ‘wss://stream.binance.com:9443/ws/btcusdt@aggTrade’
and see if you can get any response.

emmm,
After trying all the methods, I went to the coin’an official website to catch their requests through the website。
so,wss://stream.binance.com:9443 --> wss://sfstream.binance.cc/stream
and copy json string for request body:
String msg = “{“method”:“SUBSCRIBE”,“params”:[”!miniTicker@arr@3000ms",“btcusdt@aggTrade”,“btcusdt@kline_1m”,“btcusdt@depth”],“id”:2}";
then,is ok
but the link has been sending messages。
get message type is byte
[hex=1f8b0800000000000000ab56ca4c51b232d2512a4a2d2ecd2951b2ca2bcdc9a9050024480f8f16000000]
get message type is byte
[size=682 hex=1f8b08000000000000006d964d6e24210c85efc2ba84b0b131f4727e4e30c92aca22a3449a65a44956d1dc7d4c534551984dd4f964b71fcfc6f4977b7337f7fa…]
get message type is byte.

Refer to the previous code。
Although we got some characters with unknown meaning
But I was able to get through。
Thank you help me for your time

the port 9443 not use.
i use wss://sfstream.binance.cc/ws/bnbusdt@trade,then i received the data:
[size=124 hex=1f8b0800000000000000ab564a55b2522a294a4c4955d2517255b232343334353631363635323730d0510a411631b334d3512a06aa77f2730a0d760901ea2801…]
the hex is :
1f8b0800000000000000ab564a55b2522a294a4c4955d2517255b232343334353631363635323730d0510a411631b334d3512a06aa77f2730a0d760901ea2801ca1b59589a591a9a1ae9281500e58ccc4df48c0d2c817285409e819e810990190164fa3a0679bb82f4e42a59a525e614a7d602005e3ce5e37d000000.
I try to decode it:
Got some crap