Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

接收图片base64数据会断开 #52

Closed
lichao3140 opened this issue Mar 1, 2019 · 13 comments
Closed

接收图片base64数据会断开 #52

lichao3140 opened this issue Mar 1, 2019 · 13 comments

Comments

@lichao3140
Copy link

在对接平台接收平台发了的base64图片数据会自动断开

@dhhAndroid
Copy link
Owner

断开是由什么原因导致的?服务端关闭,还是出了什么异常 ?

@lichao3140
Copy link
Author

我接收其他数据都正常,后台服务器发送base64图片数据就会断开,我试用了另外一个框架demo,能够正常接收到base64数据,我安卓端没报什么异常,我开始以为是服务器那边的问题,因为服务器发送图片数据安卓这边就收不到信息,会断开。今天我试了另外一个框架正常收到。

@lichao3140
Copy link
Author

你有没有对接收数据长度进行限制,base64的数据有的有几十k

@dhhAndroid
Copy link
Owner

你调用代码贴一下,我看看

@lichao3140
Copy link
Author

好的,谢谢大神!
MyApplication里面
/**
* 初始化WebSocket
*/
private void initWebSocket() {
Config config = new Config.Builder()
.setShowLog(true, "webSocketLog")
.setClient(new OkHttpClient.Builder()
.pingInterval(10, TimeUnit.SECONDS)// 设置心跳间隔,这个是10秒检测一次
.build())
.setReconnectInterval(10, TimeUnit.SECONDS)// 设置重连
.build();
RxWebSocket.setConfig(config);
}

MainActivity 里面
RxWebSocket.get(Const.SERVER_URL)
.subscribe(new WebSocketSubscriber() {
@OverRide
protected void onOpen(@nonnull WebSocket webSocket) {
super.onOpen(webSocket);
Log.i(TAG, "onOpen:");
}

                @Override
                protected void onMessage(@NonNull String text) {
                    super.onMessage(text);
                    ManageMsg(text);
                    LogUtil.i(TAG, "onMessage:" + text);
                }

                @Override
                protected void onReconnect() {
                    super.onReconnect();
                    Log.i(TAG, "onReconnect:");
                }

                @Override
                protected void onClose() {
                    super.onClose();
                    Log.i(TAG, "onClose:");
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    Log.i(TAG, "onError:");
                }
            });

@lichao3140
Copy link
Author

依赖的是你这个版本的implementation 'com.dhh:websocket:2.1.2'

@dhhAndroid
Copy link
Owner

你重写一下 WebSocketSubscriber 的 protected void onMessage(@nonnull ByteString byteString) 方法试试,看这个 byteString 是否有消息回调

@lichao3140
Copy link
Author

protected void onMessage(@nonnull ByteString byteString) {
super.onMessage(byteString);
LogUtil.i(TAG, "onMessage:" + byteString);
}
这个收不到消息

@lichao3140
Copy link
Author

03-01 13:38:14.739 31448-31448/com.runvision.g702_sn I/WebMsg: onOpen:
03-01 13:39:17.412 31448-31448/com.runvision.g702_sn I/WebMsg: onReconnect:
03-01 13:39:17.490 31448-31448/com.runvision.g702_sn I/WebMsg: onOpen:
03-01 13:39:33.364 31448-31448/com.runvision.g702_sn I/WebMsg: 删除模板
03-01 13:39:33.374 31448-31448/com.runvision.g702_sn I/WebMsg: onMessage:{"code":"202","libId":"5064","faceId":"296011","uuid":"8620"}
其他消息都接收正常,就是有base64图片消息就连接断开连接

@dhhAndroid
Copy link
Owner

我没有遇到这种问题,也没有测试的服务器,我也不知道问题出来哪里

@lichao3140
Copy link
Author

好的谢谢大神

@dhhAndroid
Copy link
Owner

如果你们的测试服务器的URL可以给我的话,我可以帮忙测试一下,看看是什么问题导致的,不方便给的话,就算了。

@lichao3140
Copy link
Author

可以啊,方便的,我可以加你微信或者QQ吗?因为那后台要先调用接口发送心跳让设备在线,才能进行发送web socket 消息,我的扣扣同微信396229938

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants