解决swift实现的websocket与后台通信问题:websocket is disconnected: masked and rev data is not currently supported
来源:互联网 发布:外婆的澎湖湾 知乎 编辑:程序博客网 时间:2024/06/11 08:58
运行环境:使用websocket通信,客户端是iOS APP,使用swift写的websocket库Starstream2.0,在模拟器上运行,服务端是Java的spring-websocket框架。
问题描述:当客户端和服务端都按官方文档提供的标准写法写好后,出现websocket is disconnected: Invalid HTTP upgrade错误,经过一翻查找讨论,为websocket客户端这边建立链接时加上http头信息,如下:
socket.headers["Sec-WebSocket-Version"] = "13" socket.headers["Sec-WebSocket-Extensions"] = "permessage-deflate" socket.headers["Pragma"] = "no-cache" socket.headers["Cache-Control"] = "no-cache" socket.headers["Origin"] = "http://yourself ip" socket.headers["Encoding"] = "gzip,deflate,sdch" socket.headers["Accept-Language"] = "zh-CN,zh;q=0.8" socket.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER)"
之后可以建立链接,但此时iOS APP向服务端发送信息,服务端是可以正常接收解析,而服务端返回的信息,在iOS APP收到后,提示websocket is disconnected: masked and rev data is not currently supported后断开链接。在GitHub上的Starscream问题讨论区找到解决办法(checkout line: https://github.com/daltoniam/Starscream/issues/46):
//socket.headers["Sec-WebSocket-Extensions"] = "permessage-deflate" //需要去掉这里的压缩格式
之后可以正常通信。
待验证:和使用的Startscream版本有关系,我这里用的版本比较低,所以会出现这种情况,当升级到2.4.3以后这个问题会解决。
阅读全文
0 0
- 解决swift实现的websocket与后台通信问题:websocket is disconnected: masked and rev data is not currently supported
- websocket 解决 The extension [x-webkit-deflate-frame] is not supported 问题
- swift 实现websocket与后台通信(swift 如何构建简单的json字符串)
- 解决javax.websocket.DeploymentException: The path [webSocket] is not valid.
- Selenium-异常:Element is not currently visible and so may not be interacted with的解决
- Selenium-异常:Element is not currently visible and so may not be interacted with的解决
- rails and gem is currently not installed (解决)
- WebDriver遇到Element is not currently visible and so ...解决
- Redirection is not supported.解决
- WebSocket实现与服务器通信
- Eclipse连不上模拟器的问题[emulator-5554 disconnected] 与 ERROR: the user data image is used by another emulator. aborting
- Eclipse连不上模拟器的问题[emulator-5554 disconnected] 与 ERROR: the user data image is used by another emulator. aborting
- 解决eclipse中web项目出现Project facet Java version 1.8 is not supported.的问题
- 解决Project facet Java version *.* is not supported的方法
- websocket 与 tomcat websocket通信
- Project facet Java 6.0 is not supported的问题
- Project facet Java 6.0 is not supported的问题
- ssl is not supported
- react native点击事件传递参数
- Android线程—ThreadLocal
- ztree的初级使用
- 【Java实战】源码解析Java SPI(Service Provider Interface )机制原理
- RYU实战,REST API流表控制(1)
- 解决swift实现的websocket与后台通信问题:websocket is disconnected: masked and rev data is not currently supported
- MVC4 + EF 创建项目
- 第7章 预处理以及内存管理
- ftp站点下载
- java 编程思想--I/O系统(一)
- Ubuntu 16.04搭建LAMP开发环境
- C#中POST数据和接收的几种方式(抛砖引玉)
- Unity3D研究院之提取游戏资源的三个工具支持Unity5(八十四)
- vc6常见错误