Connecting to Pushbullet's Secure Websocket on Android

折月煮酒 提交于 2019-12-03 21:57:47

From that error I can only guess that it might have some issue with SSL. There is an alternative (not documented) streaming endpoint you could try that would maybe help debug this issue. If you do a request to https://stream.pushbullet.com/streaming/ACCESS_TOKEN_HERE it returns a chunked HTTP response that keeps going until you disconnect. If you can figure out how to read this streaming response (many http clients can do this) then at least that part works and it's just your websocket library.

You can use the streaming thing from the command line with curl --no-buffer. You should see a nop message immediately upon connection.

You might have an easier time using the streaming (long lived HTTP connection) instead of WebSocket on Android. Here's some sample code I have working on Android for this:

final URL url = new URL("https://stream.pushbullet.com/streaming/" + <USER_API_KEY>);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(38000);
connection.setConnectTimeout(8000);
connection.setRequestMethod("GET");
connection.setDoInput(true);

L.i("Connecting to stream server");

connection.connect();

final int responseCode = connection.getResponseCode();
if (responseCode != 200) {
    throw new QuietException("Unable to connect to stream, server returned " + responseCode);
}

final InputStream inputStream = connection.getInputStream();

try {
    final BufferedReader stream = new BufferedReader(new InputStreamReader(inputStream));

    final String line = stream.readLine();
    final JSONObject message = new JSONObject(line);
    // And now you can do something based on this message
} finally {
    inputStream.close();
}

This would work great while your app is open. If you want to get messages all the time, that's a bit harder. You'd need to receive the messages via GCM, which would mean creating a device for us to send the messages to for your app. If that's what you'd need, I suggest emailing api@pushbullet.com for more help.

As far as I can tell from the error, you are using the Draft_10 which is rather old.

You should use the current draft [Draft_17] like this :

final WebSocketClient mWebSocketClient = new WebSocketClient(uri, new Draft_17()) {

And add to imports :

import org.java_websocket.drafts.Draft_10;

If you are interested, you may find more about drafts here:

https://github.com/TooTallNate/Java-WebSocket/wiki/Drafts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!