详细问题描述
- 
uni-app下使用websocket,在IOS以及web环境下都可以正常收取文本消息和二进制消息。但是同样的程序在android环境就不能收取二进制消息,普通文本消息还是可以正常收到。 
- 
如果采用老的编译模式【usingComponents=false】,可以收到二进制消息。 
- 
初步怀疑:android平台下对于websocket二进制消息收取有问题。 
- 
基本可以排除是服务端的问题,原因 1)其他java websocket客户端,纯javascript websocket客户端都可以收发服务端发送的文本和二进制消息。 2)如果将服务端发送消息的模式从binary改为text,则android平台下可以正常收取消息。 
IDE运行环境说明
Hbuilder2.0.1到HBuilder2.1.3版本都测试过,问题都存在。
可重现代码片段
uni-app websocket
    export default {  
        data() {  
            return {  
                title: 'Hello'  
            }  
        },  
        onLoad() {  
            var socketTask = uni.connectSocket({  
                url: 'ws://192.168.202.244:9325',  
                data() {  
                    return {  
                        x: '',  
                        y: ''  
                    };  
                },  
                header: {  
                    'content-type': 'application/json'  
                },  
                method: 'GET',  
                complete: ()=> {}  
            });  
            socketTask.onOpen(function(){  
                console.log('11111');  
                setInterval(function() {  
                    socketTask.send({  
                        data:"00001"  
                    })  
                }, 3000);  
            })  
            socketTask.onMessage(function(data){  
                console.log(data)  
            })  
            socketTask.onError(function(){  
                console.log(arguments);  
            })  
        },  
        methods: {  
        }  
    }weex websocket
websocket.WebSocket('ws://192.168.202.244:9325','');  
//websocket.WebSocket('ws://echo.websocket.org');  
websocket.onopen(function(e) {  
    console.log(111);  
    setInterval(function() {  
        websocket.send("00001{}");  
    },3000);  
    console.log(222)  
})  
websocket.onmessage(function(res) {  
    console.log(3333)  
    console.log(JSON.stringify(res));  
});   
websocket.onerror(function(e) {  
    console.log(e)  
});联系方式
[QQ] 66199805
 
             
             
             
			 
                                        
                                     
                                                                     
                                                                    
 
                                                                     
                                                                     
            
ginvi (作者)
OK,使用plus-websocket没有发现问题,多谢。
2019-08-02 17:43