dhhandroid / rxwebsocket Goto Github PK
View Code? Open in Web Editor NEWAn auto reconnection-webSocket build with okhttp and rxJava
Home Page: http://blog.csdn.net/huiAndroid/article/details/78071703
An auto reconnection-webSocket build with okhttp and rxJava
Home Page: http://blog.csdn.net/huiAndroid/article/details/78071703
如题 连接websocket php后台的
RT,重连频率要是能动态设置就好了,现在是固定2秒,期望是每多连接一次重连的时间按一定系数增长。
会出一个简化版无rx的牌本吗
webSocketInfo.isOpen(),最开始我以为这个可以判断。但是好像不能通过这个来做判断。
RxWebSocketUtil 中的onMessage接收数据与 subscriber中接收到的数据不一致。例如:
onMessage中 收到 A, B 两个数据包(服务端连续发送), subscriber中接收到的数据却为:A , A (即会变为一样的数据包)
当发送消息过快时,stringInfo用的是同一个对象,如果在第一个onNext未执行的时候,第二个消息到来,会把之前的stringInfo信息覆盖,导致前一条数据丢失
请问是不是需要服务器断开连接才会回调 WebSocketSubscriber 的 onClose 方法呢?
我看源码 WebSocketSubscriber 只有在 onComplete 的时候才会回调 onClose 方法,但在 RxWebSocketUtil 中的 WebSocketOnSubscribe 类中也没发现调用 onComplete。
那么 onClose 到底是在什么情况下才会被回调呢?
RxWebSocket没有暴露websocket连接状态的同步方法;
RxWebSocketUtil.java这个文件中的getWebSocketInfo()方法,在observable已存在的情况下,是有bug的。observable没存在,用observeOn()指定了在主线程上执行,但observable已存在时却没指定。这种情况下,如果在非主线程上调用了RxWebSocket.get()方法,然后在收到websocket事件后要修改界面。那么就会是第一次没问题,但第二次就有问题,会导致app崩溃。说白了,就是会导致一个隐蔽的bug
建议不要用observeOn(),这是client要负责的事情,不应该由库负责
数据接受不完整?是有什么限制吗?
用的这种方法,请问如何判断当前websocket是否连接正常,如果不正常怎么办,是否重新创建 RxWebSocketUtil.getInstance().getWebSocketInfo(Constant.SOCKET_URL)
.compose(RxLifecycle.with(this).bindOnDestroy())
.subscribe(new WebSocketSubscriber()
RxLifecycle用着很舒服,也升级到rxjava2了,在你没升级rxjava2前我自己也实现了。
但RxWebSocket有什么方式支持Socket.IO呢? 这是我目前的困扰
如果我想在一个activity里面去手动关闭和重新打开socket该怎么做呢?
log:02-18 09:28:00.717 27760-27760/com.giada.gdsm D/TestService: 重连
02-18 09:28:00.719 27760-27786/com.giada.gdsm D/GDSM: ws://www.xxx:8081/api/MessageRelease --> cancel
02-18 09:28:00.751 27760-28074/com.giada.gdsm D/GDSM: ws://www.xxx:8081/api/MessageRelease --> onOpen
02-18 09:28:00.752 27760-27760/com.giada.gdsm D/TestService: onOpen1:
02-18 09:28:00.763 27760-28074/com.giada.gdsm E/GDSM: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)/api/MessageRelease
02-18 09:28:02.799 27760-27760/com.giada.gdsm D/TestService: 重连
02-18 09:28:02.801 27760-28074/com.giada.gdsm D/GDSM: ws://www.xxx:8081/api/MessageRelease --> cancel
02-18 09:28:02.828 27760-27786/com.giada.gdsm D/GDSM: ws://www.xxx:8081/api/MessageRelease --> onOpen
02-18 09:28:02.829 27760-27760/com.giada.gdsm D/TestService: onOpen1:
02-18 09:28:02.838 27760-27786/com.giada.gdsm E/GDSM: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)/api/MessageRelease
02-18 09:28:04.874 27760-27760/com.xxx D/TestService: 重连
02-18 09:28:04.877 27760-27786/com.giada.gdsm D/GDSM: ws://www.xxx:8081/api/MessageRelease --> cancel
02-18 09:28:04.904 27760-28074/com.giada.gdsm D/GDSM: ws://www.xxx:8081/api/MessageRelease --> onOpen
02-18 09:28:04.905 27760-27760/com.giada.gdsm D/TestService: onOpen1:
02-18 09:28:04.916 27760-28074/com.giada.gdsm E/GDSM: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)/api/MessageRelease
有没有什么办法解决发送的数据量过大时,会超出限制,进而引起程序崩溃了。
有没有办法解决?
java.net.ProtocolException: Code must be in range [1000,5000): 10000/
这个异常是什么情况啊
换成自己的URL时,URL是https
"https://xxx.xxx.cc/api/socket/opensocket?nickName=3320229879"
就会报
E/RxWebSocketUtil: java.net.ProtocolException: Expected HTTP 101 response but was '400 Bad Request'/api/socket/opensocket
我用您的连接,都么有问题,但是日志一直打印
ebSocketUtil: ws://192.168.1.33:7181 --> onClosed:code= 1000
02-01 17:30:30.483 12998-13029/cn.gygxzc.tony.asr D/RxWebSocketUtil: ws://192.168.1.33:7181 --> onOpen
02-01 17:30:30.484 12998-12998/cn.gygxzc.tony.asr I/SocketService: onOpen->okhttp3.internal.ws.RealWebSocket@43e1e1f8
02-01 17:30:33.596 12998-13236/cn.gygxzc.tony.asr D/dalvikvm: JIT unchain all for threadid=23
02-01 17:30:33.824 12998-13236/cn.gygxzc.tony.asr D/dalvikvm: GC_FOR_ALLOC freed 504K, 11% free 36741K/40840K, paused 477ms, total 477ms
02-01 17:30:39.777 12998-13242/cn.gygxzc.tony.asr D/dalvikvm: JIT unchain all for threadid=23
02-01 17:30:40.005 12998-13242/cn.gygxzc.tony.asr D/dalvikvm: GC_FOR_ALLOC freed 475K, 11% free 36742K/40840K, paused 477ms, total 477ms
02-01 17:30:40.501 12998-13029/cn.gygxzc.tony.asr D/RxWebSocketUtil: ws://192.168.1.33:7181 --> onClosed:code= 1000
02-01 17:30:42.508 12998-13029/cn.gygxzc.tony.asr D/RxWebSocketUtil: ws://192.168.1.33:7181 --> onOpen
02-01 17:30:42.509 12998-12998/cn.gygxzc.tony.asr I/SocketService: onOpen->okhttp3.internal.ws.RealWebSocket@43e1d120
能请问一下这个属于什么情况吗?
这里断开连接不能使用。
断开连接
如题,服务器重启后,前端不会发启重连,是服务器需要告诉前端断连了吗?要重启app才能连接上。
源码中doOnDispose()方法只是把url从map中remove掉了,比如我需要在ondetory方法中关闭掉websocket连接,是直接取消订阅即可 还是需要关闭连接 再取消订阅?
/**
* @param url ws://127.0.0.1:8080/websocket
* @param timeout The WebSocket will be reconnected after the specified time interval is not "onMessage",
*
* 在指定时间间隔后没有收到消息就会重连WebSocket,为了适配小米平板,因为小米平板断网后,不会发送错误通知
* @param timeUnit unit
* @return
*/
public Observable getWebSocketInfo(final String url, final long timeout, final TimeUnit timeUnit) {
Observable observable = observableMap.get(url);
if (observable == null) {
observable = Observable.create(new WebSocketOnSubscribe(url))
//自动重连
.timeout(timeout, timeUnit)
.retry()
//共享
.doOnDispose(new Action() {
@OverRide
public void run() throws Exception {
observableMap.remove(url);
webSocketMap.remove(url);
if (showLog) {
Log.d("RxWebSocketUtil", "注销");
}
}
})
.doOnNext(new Consumer() {
@OverRide
public void accept(WebSocketInfo webSocketInfo) throws Exception {
if (webSocketInfo.isOnOpen()) {
webSocketMap.put(url, webSocketInfo.getWebSocket());
}
}
})
.share()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
observableMap.put(url, observable);
} else {
observable = Observable.merge(Observable.just(new WebSocketInfo(webSocketMap.get(url), true)), observable);
}
return observable;
Device: HUAWEI STF-AL00
Stack trace:
io.reactivex.exceptions.UndeliverableException: java.net.SocketException: Software caused connection abort
at io.reactivex.e.a.a(RxJavaPlugins.java:367)
at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.onError(ObservableCreate.java:74)
at com.dhh.websocket.d$a$1.onFailure(RxWebSocketUtil.java:354)
at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:570)
at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:215)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:784)
Caused by: java.net.SocketException: Software caused connection abort
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:114)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:139)
at okio.Okio$2.read(Okio.java:140)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
at okio.RealBufferedSource.request(RealBufferedSource.java:68)
at okio.RealBufferedSource.require(RealBufferedSource.java:61)
at okio.RealBufferedSource.readByte(RealBufferedSource.java:74)
at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.java:117)
at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:101)
at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:273)
at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:213)
... 5 more
当webSocket数据频率很快是,就会报出rx.exceptions.MissingBackpressureException 的异常
2 io.reactivex.internal.functions.ObjectHelper.requireNonNull(ObjectHelper.java:39)
3 ......
4 Caused by:
5 java.lang.Throwable:
6 io.reactivex.Observable.map(Observable.java:8814)
7 com.demo.common.rxwebsocket.RxWebSocketUtil.getWebSocket(RxWebSocketUtil.java:222)
8 com.demo.common.rxwebsocket.RxWebSocketUtil.asyncSend(RxWebSocketUtil.java:271)
9 com.demo.common.rxwebsocket.RxWebSocket.asyncSend(RxWebSocket.java:77)
10 com.demo.ui.contact.jobs.GetContactInfoJob.onRun(GetContactInfoJob.java:69)
11 com.birbit.android.jobqueue.Job.safeRun(Job.java:229)
public Observable getWebSocket(String url) {
return getWebSocketInfo(url)
.map(new Function<WebSocketInfo, WebSocket>() {
@OverRide
public WebSocket apply(@nonnull WebSocketInfo webSocketInfo) throws Exception {
return webSocketInfo.getWebSocket();
}
});
}
getWebSocketInfo(url)这一行报错了,怎么解决?
如何获取websocket连接状态,isOnOpen 在连接之后好像就变为false了
如题,怎样支持wss
大哥,请问Ping 需要自已写定时器去ping吗?
我看代码里有这句
// ping/pong 设置:在设置config的时候,从okhttpclient中配置:(将此client设置到上面的config中)
OkHttpClient client = new OkHttpClient.Builder().pingInterval(6, TimeUnit.MINUTES).build();
设置了pingInterval 是不是会自动去Ping?
在对接平台接收平台发了的base64图片数据会自动断开
OPPO R9sk Android6.0 连不上长链接,一直重连执行onReconnect方法,onError没有进,看不到错误日志,其他手机却可以连接。
不好意思,我沒什麼android studio的經驗,我直接從android studio 裡clone project, 但在Sync project with gradle files 時出現問題,以下是console 的error log,請問有頭緒嗎?Android studio 的版本是3.1.2
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'RxWebSocket'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:94)
at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:66)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access$100(LifecycleProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator$ConfigureProject.run(LifecycleProjectEvaluator.java:110)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:666)
at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:135)
at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:60)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
at org.gradle.initialization.DefaultGradleLauncher$ConfigureBuild.run(DefaultGradleLauncher.java:249)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.initialization.DefaultGradleLauncher.configureBuild(DefaultGradleLauncher.java:167)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:126)
at org.gradle.initialization.DefaultGradleLauncher.getConfiguredBuild(DefaultGradleLauncher.java:104)
at org.gradle.internal.invocation.GradleBuildController$2.call(GradleBuildController.java:87)
at org.gradle.internal.invocation.GradleBuildController$2.call(GradleBuildController.java:84)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
at org.gradle.internal.invocation.GradleBuildController.configure(GradleBuildController.java:84)
at org.gradle.tooling.internal.provider.runner.ClientProvidedBuildActionRunner.run(ClientProvidedBuildActionRunner.java:64)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:69)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:30)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:45)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.rethrowFailure(DefaultConfiguration.java:918)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.access$1600(DefaultConfiguration.java:116)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:892)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getFiles(DefaultConfiguration.java:404)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getFiles(Unknown Source)
at org.gradle.api.internal.file.AbstractFileCollection.iterator(AbstractFileCollection.java:68)
at org.gradle.internal.classpath.DefaultClassPath.(DefaultClassPath.java:48)
at org.gradle.api.internal.initialization.DefaultScriptClassPathResolver.resolveClassPath(DefaultScriptClassPathResolver.java:39)
at org.gradle.api.internal.initialization.DefaultScriptHandler.getScriptClassPath(DefaultScriptHandler.java:72)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.defineScriptHandlerClassScope(DefaultPluginRequestApplicator.java:204)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:82)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:179)
at org.gradle.configuration.BuildOperationScriptPlugin$1.run(BuildOperationScriptPlugin.java:61)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:58)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:41)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:64)
... 84 more
Caused by: org.gradle.internal.resolve.ArtifactNotFoundException: Could not find gradle.jar (com.android.tools.build:gradle:3.1.2).
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.jar
at org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult.notFound(DefaultBuildableArtifactResolveResult.java:27)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver$RemoteRepositoryAccess.resolveArtifact(ExternalResourceResolver.java:501)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository$ResolveAndCacheRepositoryAccess.resolveArtifact(CachingModuleComponentRepository.java:409)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.BaseModuleComponentRepositoryAccess.resolveArtifact(BaseModuleComponentRepositoryAccess.java:65)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.InMemoryCachedModuleComponentRepository$CachedAccess.resolveArtifact(InMemoryCachedModuleComponentRepository.java:124)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingModuleComponentRepository$ErrorHandlingModuleComponentRepositoryAccess.resolveArtifact(ErrorHandlingModuleComponentRepository.java:171)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainArtifactResolver.resolveArtifact(RepositoryChainArtifactResolver.java:80)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DefaultArtifactSet$LazyArtifactSource.create(DefaultArtifactSet.java:171)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DefaultArtifactSet$LazyArtifactSource.create(DefaultArtifactSet.java:158)
at org.gradle.api.internal.artifacts.DefaultResolvedArtifact.getFile(DefaultResolvedArtifact.java:135)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactBackedResolvedVariant$DownloadArtifactFile.run(ArtifactBackedResolvedVariant.java:146)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.access$900(DefaultBuildOperationExecutor.java:63)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$ParentPreservingQueueWorker.execute(DefaultBuildOperationExecutor.java:378)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runOperation(DefaultBuildOperationQueue.java:230)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.access$600(DefaultBuildOperationQueue.java:172)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable$1.call(DefaultBuildOperationQueue.java:209)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable$1.call(DefaultBuildOperationQueue.java:203)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runBatch(DefaultBuildOperationQueue.java:202)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.run(DefaultBuildOperationQueue.java:177)
... 6 more
Could not find gradle.jar (com.android.tools.build:gradle:3.1.2).
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.jar
从目前的测试来看:
,当app网络异常,websocket 会断开,恢复网络后,再重连,后台会新建一个session,即每次断线重连,会增加seesion,断线重连到达一定次数时,后台不会挂吗?
io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | javax.net.ssl.SSLException: Read error: ssl=0xc17bda80: I/O error during system call, Software caused connection abort
at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.onError(ObservableCreate.java:73)
at com.base.library.b.b.b$a$1.onFailure(RxWebSocketUtil.java:361)
at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:571)
at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:216)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:784)
Caused by : javax.net.ssl.SSLException: Read error: ssl=0xc17bda80: I/O error during system call, Software caused connection abort
com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
com.android.org.conscrypt.SslWrapper.read(SslWrapper.java:384)
com.android.org.conscrypt.ConscryptFileDescriptorSocket$SSLInputStream.read(ConscryptFileDescriptorSocket.java:541)
okio.o$2.read(Okio.java:140)
okio.a$2.read(AsyncTimeout.java:237)
okio.s.b(RealBufferedSource.java:68)
okio.s.a(RealBufferedSource.java:61)
okio.s.i(RealBufferedSource.java:74)
okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.java:117)
okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:101)
okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:274)
okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:214)
请问Application里初始化的全局websocket 如何关闭?使用
Disposable disposable = RxWebSocket.get(BASE_URL).subscribe();
if (disposable != null) {
disposable.dispose();
}
关闭后会自动重连,Rxjava2版本
因为项目IM和接口请求共用的
//注销方法。但是并不能关闭此连接
Disposable disposable = RxWebSocket.get(url).subscribe();
if (disposable != null && !disposable.isDisposed()) {
disposable.dispose();
}
操作如下,连接成后,再断开网络,会自动重新连接,一直回调
@OverRide
protected void onReconnect() {
super.onReconnect();
}
然后 手动调用注销方法,但是并不能结束掉这个连接,还会一直回调重连机制
implementation 'com.dhh:websocket:2.1.2' 可以,any idea?
用RxLifecycle然后写在onResume里吗
02-28 17:25:56.221 14313-14313/com.dhh.rxwebsocket V/AudioManager: playSoundEffect effectType: 0
02-28 17:25:56.221 14313-14313/com.dhh.rxwebsocket V/AudioManager: querySoundEffectsEnabled...
02-28 17:25:56.224 14313-14433/com.dhh.rxwebsocket D/MainActivity: 收到客户端消息:hello
02-28 17:25:56.225 14313-14433/com.dhh.rxwebsocket D/MainActivity: 收到客户端消息:hello
02-28 17:25:56.229 14313-14313/com.dhh.rxwebsocket D/MainActivity: Server response:hello
02-28 17:25:56.233 14313-14313/com.dhh.rxwebsocket D/MainActivity: Server response:hello
有时候虽然绑定了Activity的生命周期,但是有时候希望在Activity生命周期内的某一段时间暂时关闭websocket链接
java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add onError
handling.
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:112)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: rx.exceptions.OnErrorNotImplementedException: Attempt to invoke interface method 'boolean okhttp3.WebSocket.send(java.lang.String)' on a null object reference
at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:386)
at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:383)
at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44)
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:212)
at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:139)
at rx.internal.producers.SingleProducer.request(SingleProducer.java:65)
at rx.Subscriber.setProducer(Subscriber.java:209)
at rx.Subscriber.setProducer(Subscriber.java:205)
at rx.internal.operators.OperatorSingle$ParentSubscriber.onCompleted(OperatorSingle.java:110)
at rx.internal.operators.OperatorTake$1.onNext(OperatorTake.java:80)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:224)
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:107)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean okhttp3.WebSocket.send(java.lang.String)' on a null object reference
at com.dhh.websocket.RxWebSocketUtil$8.call(RxWebSocketUtil.java:268)
at com.dhh.websocket.RxWebSocketUtil$8.call(RxWebSocketUtil.java:265)
at rx.internal.util.ActionSubscriber.onNext(ActionSubscriber.java:39)
at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:134)
at rx.internal.producers.SingleProducer.request(SingleProducer.java:65)
at rx.Subscriber.setProducer(Subscriber.java:209)
at rx.Subscriber.setProducer(Subscriber.java:205)
at rx.internal.operators.OperatorSingle$ParentSubscriber.onCompleted(OperatorSingle.java:110)
at rx.internal.operators.OperatorTake$1.onNext(OperatorTake.java:80)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:224)
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:107)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
按照例子加入代码
在重连的时候,多次调用asyncsend方法 报错crash
部分手机断网或者更改网络后,socket不会受到close 或者 fail回调,这种情况怎么判断是否已连接状态呢?因为调用send方法会retrun true,实际上无法发送消息和无法接受消息
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.