- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 iOS 应用程序与 Node.js WebSocket 服务器集成。我在 iOS 上使用 SwiftUI,在服务器和客户端上使用 socket.io。
但是当我尝试将 iOS 应用程序与服务器连接时,好像连不上服务器。
我通过将 React 应用程序连接到 Node.js 服务器来测试服务器是否正在运行并且连接在浏览器中运行良好。
我检查了 swift 日志,它似乎在尝试与服务器握手,但是,它开始长轮询,所以我猜握手过程有一些问题。
如果有新连接,我会在 Node.js 服务器中将“新连接”作为字符串记录到控制台,并且它对 React 但对 Swift 工作正常。
但我没有提前尝试任何事情,所以我无法找出问题所在。
有人可以帮我吗?
import SwiftUI
import SocketIO
final class Service: ObservableObject {
private var manager = SocketManager(socketURL:URL(string: "http://localhost:5000")!, config: [.log(true), .compress])
init() {
let socket = manager.defaultSocket
socket.on(clientEvent: .connect) { (data,act) in
print("Connected")
}
socket.connect()
}
}
struct SocketIO: View {
@ObservedObject var service = Service()
var body: some View {
Text("Hello, Web socket!")
}
}
这是我从 SocketIO-client-swift 获得的日志
2020-12-18 13:08:24.033132+0900 Tests[4397:171225] LOGSocketIOClient{/}: Adding handler for event: connect 2020-12-1813:08:24.033663+0900 Tests[4397:171225] LOG SocketIOClient{/}:Handling event: statusChange with data: [connecting, 2] 2020-12-1813:08:24.033811+0900 Tests[4397:171225] LOG SocketIOClient{/}: Joiningnamespace / 2020-12-18 13:08:24.033930+0900 Tests[4397:171225] LOGSocketManager: Tried connecting socket when engine isn't open.Connecting 2020-12-18 13:08:24.034033+0900 Tests[4397:171225] LOGSocketManager: Adding engine 2020-12-18 13:08:24.035507+0900Tests[4397:171427] LOG SocketEngine: Starting engine. Server:http://localhost:5000 2020-12-18 13:08:24.035608+0900Tests[4397:171427] LOG SocketEngine: Handshaking 2020-12-1813:08:24.038113+0900 Tests[4397:171427] LOG SocketEnginePolling: Doingpolling GET http://localhost:5000/socket.io/?transport=polling&b64=12020-12-18 13:08:24.125554+0900 Tests[4397:171431] []nw_protocol_get_quic_image_block_invoke dlopen libquic failed2020-12-18 13:08:24.166652+0900 Tests[4397:171427] LOGSocketEnginePolling: Got polling response 2020-12-1813:08:24.166801+0900 Tests[4397:171427] LOG SocketEnginePolling: Gotpoll message:0{"sid":"97Fb8N3Ub5ZuRlfHAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2020-12-18 13:08:24.168076+0900 Tests[4397:171427] LOG SocketEngine:Got message:0{"sid":"97Fb8N3Ub5ZuRlfHAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2020-12-18 13:08:24.171813+0900 Tests[4397:171225] LOGSocketIOClient{/}: Handling event: ping with data: [] 2020-12-1813:08:24.171845+0900 Tests[4397:171427] LOG SocketEnginePolling: Doingpolling GEThttp://localhost:5000/socket.io/?transport=polling&b64=1&sid=97Fb8N3Ub5ZuRlfHAAAA2020-12-18 13:08:24.172148+0900 Tests[4397:171225] LOG SocketManager:Engine opened Connect 2020-12-18 13:08:24.172267+0900Tests[4397:171225] LOG SocketIOClient{/}: Socket connected 2020-12-1813:08:24.172485+0900 Tests[4397:171225] LOG SocketIOClient{/}:Handling event: statusChange with data: [connected, 3] 2020-12-1813:08:24.172704+0900 Tests[4397:171225] LOG SocketIOClient{/}:Handling event: connect with data: ["/"] Connected 2020-12-1813:08:24.174125+0900 Tests[4397:171427] LOG SocketEngine: Writingpoll: has data: false 2020-12-18 13:08:24.174260+0900Tests[4397:171427] LOG SocketEnginePolling: Sending poll: as type: 22020-12-18 13:08:24.174607+0900 Tests[4397:171427] LOGSocketEnginePolling: Created POST string: 1:2 2020-12-1813:08:24.175188+0900 Tests[4397:171427] LOG SocketEnginePolling:POSTing 2020-12-18 13:08:24.175708+0900 Tests[4397:171427] LOGSocketEnginePolling: Doing polling POSThttp://localhost:5000/socket.io/?transport=polling&b64=1&sid=97Fb8N3Ub5ZuRlfHAAAA2020-12-18 13:08:24.181566+0900 Tests[4397:171225] LOGSocketIOClient{/}: Handling event: websocketUpgrade with data:[["upgrade": "websocket", "connection": "Upgrade","sec-websocket-accept": "DK4ZA/luKjOL11P+2vm4APQNE5I="]] 2020-12-1813:08:24.181780+0900 Tests[4397:171429] LOG SocketEngineWebSocket:Sending ws: probe as type: 2 2020-12-18 13:08:24.183557+0900Tests[4397:171431] LOG SocketEnginePolling: Got polling response2020-12-18 13:08:24.183723+0900 Tests[4397:171431] LOGSocketEnginePolling: Doing polling GEThttp://localhost:5000/socket.io/?transport=polling&b64=1&sid=97Fb8N3Ub5ZuRlfHAAAA2020-12-18 13:08:24.184529+0900 Tests[4397:171427] LOG SocketEngine:Flushing probe wait 2020-12-18 13:08:24.186620+0900 Tests[4397:171428]ERROR SocketEnginePolling: Error during long poll request 2020-12-1813:08:24.186736+0900 Tests[4397:171428] ERROR SocketEngine: Error2020-12-18 13:08:24.186892+0900 Tests[4397:171225] ERRORSocketManager: Error 2020-12-18 13:08:24.186907+0900Tests[4397:171428] LOG SocketEngine: Engine is being closed.2020-12-18 13:08:24.187029+0900 Tests[4397:171225] LOGSocketIOClient{/}: Handling event: error with data: ["Error"]2020-12-18 13:08:24.187306+0900 Tests[4397:171428] LOGSocketEnginePolling: Created POST string: 1:1 2020-12-1813:08:24.187548+0900 Tests[4397:171428] LOG SocketEnginePolling: Doingpolling POSThttp://localhost:5000/socket.io/?transport=polling&b64=1&sid=97Fb8N3Ub5ZuRlfHAAAA2020-12-18 13:08:24.188161+0900 Tests[4397:171225] LOG SocketManager:Starting reconnect 2020-12-18 13:08:24.188342+0900 Tests[4397:171225]LOG SocketIOClient{/}: Handling event: statusChange with data:[connecting, 2] 2020-12-18 13:08:24.188558+0900 Tests[4397:171225] LOGSocketIOClient{/}: Handling event: reconnect with data: ["Error"]2020-12-18 13:08:24.188729+0900 Tests[4397:171225] LOG SocketManager:Trying to reconnect 2020-12-18 13:08:24.188830+0900 Tests[4397:171225]LOG SocketIOClient{/}: Handling event: reconnectAttempt with data:[-1] 2020-12-18 13:08:24.189043+0900 Tests[4397:171429] LOGSocketEngine: Starting engine. Server: http://localhost:50002020-12-18 13:08:24.189113+0900 Tests[4397:171225] LOG SocketManager:Scheduling reconnect in 15.068159317825785s 2020-12-1813:08:24.189439+0900 Tests[4397:171429] LOG SocketEngine: Handshaking2020-12-18 13:08:24.189732+0900 Tests[4397:171429] LOGSocketEnginePolling: Doing polling GEThttp://localhost:5000/socket.io/?transport=polling&b64=1 2020-12-1813:08:24.197564+0900 Tests[4397:171432] LOG SocketEnginePolling: Gotpolling response 2020-12-18 13:08:24.197690+0900 Tests[4397:171432]LOG SocketEnginePolling: Got poll message:0{"sid":"7RPKclRosgovPKY5AAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2020-12-18 13:08:24.197839+0900 Tests[4397:171432] LOG SocketEngine:Got message:0{"sid":"7RPKclRosgovPKY5AAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2020-12-18 13:08:24.198569+0900 Tests[4397:171225] LOGSocketIOClient{/}: Handling event: ping with data: [] 2020-12-1813:08:24.198587+0900 Tests[4397:171432] LOG SocketEnginePolling: Doingpolling GEThttp://localhost:5000/socket.io/?transport=polling&b64=1&sid=7RPKclRosgovPKY5AAAB2020-12-18 13:08:24.198671+0900 Tests[4397:171225] LOG SocketManager:Engine opened Connect 2020-12-18 13:08:24.198848+0900Tests[4397:171225] LOG SocketIOClient{/}: Socket connected 2020-12-1813:08:24.199022+0900 Tests[4397:171225] LOG SocketIOClient{/}:Handling event: statusChange with data: [connected, 3] 2020-12-1813:08:24.199197+0900 Tests[4397:171225] LOG SocketIOClient{/}:Handling event: connect with data: ["/"] Connected 2020-12-1813:08:24.199445+0900 Tests[4397:171432] LOG SocketEngine: Writingpoll: has data: false 2020-12-18 13:08:24.199714+0900Tests[4397:171432] LOG SocketEnginePolling: Sending poll: as type: 22020-12-18 13:08:24.199973+0900 Tests[4397:171432] LOGSocketEnginePolling: Created POST string: 1:2 2020-12-1813:08:24.200257+0900 Tests[4397:171432] LOG SocketEnginePolling:POSTing 2020-12-18 13:08:24.200524+0900 Tests[4397:171432] LOGSocketEnginePolling: Doing polling POSThttp://localhost:5000/socket.io/?transport=polling&b64=1&sid=7RPKclRosgovPKY5AAAB2020-12-18 13:08:24.205180+0900 Tests[4397:171225] LOGSocketIOClient{/}: Handling event: websocketUpgrade with data:[["upgrade": "websocket", "connection": "Upgrade","sec-websocket-accept": "e5m4DoLk6GlrzUzZSHtQ/n0gXl0="]] 2020-12-1813:08:24.205309+0900 Tests[4397:171429] LOG SocketEngineWebSocket:Sending ws: probe as type: 2 2020-12-18 13:08:24.207171+0900Tests[4397:171429] LOG SocketEngine: Got message: 3probe 2020-12-1813:08:24.207420+0900 Tests[4397:171429] LOG SocketEngine: Receivedprobe response, should upgrade to WebSockets 2020-12-1813:08:24.207622+0900 Tests[4397:171429] LOG SocketEngine: Upgradingtransport to WebSockets 2020-12-18 13:08:24.209704+0900Tests[4397:171429] LOG SocketEnginePolling: Sending poll: as type: 62020-12-18 13:08:24.210114+0900 Tests[4397:171225] LOGSocketIOClient{/}: Handling event: pong with data: [] 2020-12-1813:08:24.210826+0900 Tests[4397:171431] LOG SocketEngine: Flushingprobe wait 2020-12-18 13:08:24.211131+0900 Tests[4397:171431] LOGSocketEnginePolling: Got polling response 2020-12-1813:08:24.211279+0900 Tests[4397:171431] LOG SocketEngine: Switching toWebSockets 2020-12-18 13:08:24.211500+0900 Tests[4397:171431] LOGSocketEngineWebSocket: Sending ws: as type: 5 2020-12-1813:08:24.211974+0900 Tests[4397:171431] LOG SocketEngine: Flushingprobe wait
最佳答案
这可能与安全有关。通常 ios 应用程序期望使用 https 进行连接。要允许 http 连接,请在您的info.plist 添加这个(临时安全修复):
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
关于node.js - 使用 Swift 的 Socket.io 不是握手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65351721/
在 firefox 中,链接手形光标显示正常,但在 IE7 中显示文本光标。 如何在所有浏览器的链接上获得相同的光标(手)? 我可以在 CSS 重置中添加一些内容,以便在所有浏览器中的链接上获取光标吗
我试图在表单元素上方显示我的表单标签,所以我在我的 CSS 中使用了 display:block。但是,我无法通过这种方式每行显示超过 1 个表单元素。 如何正确更新我的 CSS 以在表单元素上方显示
我想找到人手的宽度,但卡在手上的洞上。 我有一只手的图片并找到了它的二进制文件。手上有一个圆圈,其半径和中心已知(引用对象)。我想找到手的宽度,但它上面有一些补丁(孔),这阻碍了找到手的最佳宽度。 这
我尝试为一款游戏制作一个机器人,但他们有很酷的反像素机器人技术。 所以我想,“如果我可以制作一个机器人,只检查光标是否变为手形然后单击,它就会起作用,”因为我需要收集奖金盒,当你将光标指向它时,它变为
我尝试为一款游戏制作一个机器人,但他们有很酷的反像素机器人技术。 所以我想,“如果我可以制作一个机器人,只检查光标是否变为手形然后单击,它就会起作用,”因为我需要收集奖金盒,当你将光标指向它时,它变为
所以我有一副牌的代码,但我不知道如何让另一个类来处理 4 手牌,每手 10 张牌。另一类应在屏幕上以文字形式打印 4 手 10 张随机卡片。有人可以向我展示如何完成此任务的代码吗?我也使用 blueJ
我正在尝试通过在开放正方形内插入图标来使用 fontawesome 创建图标。悬停时,我想更改正方形内背景的颜色,以及正方形的实际颜色和图标颜色。 我在这里举了一个例子:http://jsfiddle
当我手动启 Action 业时,我正在寻找设置变量的正确方法。 我试过 : stages: - test my_job: stage: test script: - echo "H
我必须添加以下代码: a {cursor:pointer;} 在 angular-ui-bootstrap 中将光标更改为标签、分页、下拉切换等链接上的指针/手。 为什么默认不改为指针?这是故意的吗?
我是一名优秀的程序员,十分优秀!