Reputation: 41
I already have SDK with WS connection, but it has no method to close it. In documentation has been said:
* @deprecated This method is no longer functional. Please use the returned {@link Closeable} from any of the other methods to close the web socket.
@Override
public void close() { }
private Closeable createNewWebSocket(String channel, BinanceApiWebSocketListener<?> listener) {
String streamingUrl = String.format("%s/%s", BinanceApiConfig.getStreamApiBaseUrl(), channel);
Request request = new Request.Builder().url(streamingUrl).build();
final WebSocket webSocket = client.newWebSocket(request, listener);
return () -> {
final int code = 1000;
listener.onClosing(webSocket, code, null);
webSocket.close(code, null);
listener.onClosed(webSocket, code, null);
};
}
So, how can I write close function to close my connection? Or get this @link Closeable? https://github.com/binance-exchange/binance-java-api/blob/8d38e8e63c8bf125aff963bac0284961af0630e6/src/main/java/com/binance/api/client/impl/BinanceApiWebSocketClientImpl.java
Upvotes: 4
Views: 757
Reputation: 121
It seams to me that the method returns with the Closeable. And this is true for not just the createNewWebSocket(..)...
In the github readme they explain it this way: https://github.com/binance-exchange/binance-java-api#closing-web-sockets
Closable ws = client.onAggTradeEvent("ethbtc", someCallback);
// some time later...
ws.close();
So you should not close the client
, but the called method's return-object (the Closable ws
).
In the the link you posted, it looks like many methods return with such Closeables.
Upvotes: 1