Comments (6)
我懂你意思了,你把这个 WebSocketSubscriber,作为一个成员变量,这样用,方案不一样:
private WebSocketSubscriber webSocketSubscriber;
public void openWebSocket() {
webSocketSubscriber = new WebSocketSubscriber() {
@Override
protected void onMessage(String text) {
}
@Override
protected void onReconnect() {
Log.d("MainActivity", "重连");
}
};
RxWebSocket.get("your url")
.subscribe(webSocketSubscriber);
}
public void closeWebSocket() {
if (webSocketSubscriber != null) {
webSocketSubscriber.dispose();
}
}
from rxwebsocket.
不是这样注销的,是你在调用RxWebSocket.get(url)那里订阅后,会返回一个 disposable,你要用这个disposable调用取消订阅的方法,这个是RxJava2相关的知识,你可以在网上查一下
from rxwebsocket.
类似下面的代码:
private Disposable mDisposable;
public void openWebSocket() {
mDisposable = RxWebSocket.get("your url");
.subscribe(new WebSocketSubscriber() {
@Override
protected void onMessage(String text) {
}
@Override
protected void onReconnect() {
Log.d("MainActivity", "重连");
}
});
}
public void closeWebSocket() {
if (mDisposable != null) {
mDisposable.dispose();
}
}
from rxwebsocket.
mDisposable = RxWebSocket.get("your url");
.subscribe(new WebSocketSubscriber() {
@OverRide
protected void onMessage(String text) {
}
@Override
protected void onReconnect() {
Log.d("MainActivity", "重连");
}
});
是得不到 Disposable 的
因为 public final void subscribe(Observer<? super T> observer)
from rxwebsocket.
我懂你意思了,你把这个 WebSocketSubscriber,作为一个成员变量,这样用,方案不一样:
当用这种方式dispose,close等方法都不会再调用,业务层还得自己处理close逻辑~
from rxwebsocket.
我想问一下,这样做 能真正断开 后台的连接吗?会不会后台 实际还连接着,只是前端没有了监听器而已?
from rxwebsocket.
Related Issues (20)
- 服务端的源码能否分享一下? HOT 1
- 不行啊,虽然是可以新开dispose,但是我看了本质还是同一个连接啊 HOT 4
- 断网重连方法回调的问题 HOT 1
- SocketException 后一直无法重连 HOT 2
- disposable.dispose()方法不回调onclose吗 HOT 3
- onClosing方法收到一个1011错误码后不重连 HOT 3
- 急!!!!长时间熄屏或者其他情况无消息 HOT 2
- timeout 连接 开销有点大 HOT 1
- 心跳检测 HOT 2
- 你好!发现发送大文件会失败,发送小点的图片可以,怎样可以监听发送文件的进度? HOT 1
- 服务器发布,应用会崩溃 HOT 1
- 我想一个url 多个连接咋办 HOT 3
- onReconnect()重连成功后,不会停止重连?
- setCancellable 会立即执行 HOT 7
- WebSocket连接过程中,切换wifi,重连之后再dispose无法断开WebSocket HOT 1
- 接锅回调存在多个 HOT 1
- fragment 调用注销后没有成功注销 HOT 5
- 没有失败回调 HOT 4
- RxWebsocket引起java.io.EOFException
- 开启混淆之后RxWebSocket无法使用
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxwebsocket.