Websockets 仅接收 PONG 响应

Websockets only PONG responses are received

我已经实施了 SocketRocket for websocket communication in my app but as this library is too old and archived for now, we decided to implement StarScream,这似乎是值得信赖的。

然而,在我从 SocketRocket => StarScream 迁移后,我发现我的 websockets 只收到 PONG 响应,其他请求没有得到响应。

有人能帮我找到问题或纠正我吗?

这是我的 SocketRocket implementation 即使在当前的实时生产应用程序中,我的 websockets 也能正常工作。

这是我的 StarScream implementation 即使使用生产配置也无法正常工作,我对两个应用程序使用相同的生产配置,但 SocketRocket 可以工作而 StarScream 失败。

如果您检查代码,您会发现这两种实现有很多相似之处,即使我没有收到对 StarScream 实现的正确响应。我尝试每 2 秒发送一次 ping 请求,我收到 PONG 响应,但我也会发送 auth 请求,一旦套接字连接,我在 SocketRocket 中从未收到任何响应,我确实收到了 auth 响应请求。

注意: Commenting/uncommenting sendPing()connectQuickStashSocket() 不会更改响应,代码行为相同。

我在这里附加了 SocketRocket 的日志,您将在其中看到所有 request/response 工作正常:

>>>> Connected to Socket
Optional("d2ee02da-e4de-4593-90e6-36598c00982d")
>>>> 
{
  "kind" : "auth",
  "uuid" : "",
  "auth" : {
    "version" : "1.4.0",
    "privateKey" : "d2ee02da-e4de-4593-90e6-36598c00982d",
    "device" : {
      "type" : "ios",
      "properties" : [

      ],
      "id" : "A5F24445-C688-43B0-98C1-96C636EFA08F"
    }
  }
}
>>>> Finished receiving socket data in 0.0020380020141601562 seconds
>>>> Deserialized pong data of length 25 in 0.0008620023727416992 seconds
>>>> Finished receiving socket data in 0.33321893215179443 seconds
>>>> Deserialized auth data of length 95 in 7.49826431274414e-05 seconds
>>>> 
{
  "sync" : {
    "collections" : {
      "24191c17-463c-4de9-b718-cad41976460c:stash" : {
        "cache" : {
          "e4d4804e-07a4-49f5-91f4-1b65935d4d8e" : 1,
          "8834da09-a26d-4a0f-806a-f3c54fff175e" : 1,
          "98a01deb-cfc7-4939-a6ce-d2dc64afe3a8" : 1,
          "80986d67-e0a4-4f4d-85c0-e263989f0044" : 1,
          "dd54420d-553b-4f43-808e-6cbdfcd0fe76" : 1,
          "1da73786-da7c-4b3f-b99f-58b907d15cc2" : 2,
          "c32c0a9a-c754-412e-af42-b8859a56ca72" : 1
        }
      },
      "24191c17-463c-4de9-b718-cad41976460c:inbox" : {
        "cache" : {

        }
      }
    }
  },
  "kind" : "sync"
}
>>>> Finished receiving socket data in 0.421644926071167 seconds
>>>> Deserialized sync data of length 2473 in 0.000841975212097168 seconds
Processed json and written to realm in 0.0073059797286987305 seconds
Initial state processed

这是 StarScream 的日志,其中仅收到 PONG 而未收到 auth 请求的响应,它仅显示作为请求写入的数据:

>>>> websocket is connected: ["Upgrade": "websocket", "Access-Control-Allow-Credentials": "true", "Date": "Tue, 12 May 2020 16:55:18 GMT", "Expect-CT": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"", "cf-request-id": "02ab68f8400000dcd233395200000001", "Access-Control-Allow-Origin": "wss://mercury.speare.io", "CF-Cache-Status": "DYNAMIC", "CF-RAY": "5925aaa06d91dcd2-SIN", "Sec-WebSocket-Accept": "szN0nnvUplvghVle+n4FXOFp2cw=", "Server": "cloudflare", "Connection": "upgrade"]
Connected to Socket
Optional("d2ee02da-e4de-4593-90e6-36598c00982d")
{
  "kind" : "auth",
  "auth" : {
    "privateKey" : "d2ee02da-e4de-4593-90e6-36598c00982d",
    "version" : "1.4.0",
    "device" : {
      "id" : "A5F24445-C688-43B0-98C1-96C636EFA08F",
      "type" : "ios",
      "properties" : [

      ]
    }
  },
  "uuid" : ""
}
>>>> Received data: 47
Finished receiving socket data in 0.0007439851760864258 seconds
Deserialized data pong of length 25 in 0.0006880760192871094 seconds
2020-05-12 22:25:18.520913+0530 Stash[3952:884630] Socket done writing data => auth

请在这里建议我可以做什么以及如何跟踪实际问题。

我遇到了不同的错误,这是我在本地机器上设置开发环境并在那里连接 websockets 后才知道的。

我检查了服务器的日志,发现它给我 zlib - gzip : invalid header

所以,问题是服务器没有发送任何响应,因为它没有收到格式正确的请求。

我通过 POD 更新了 gzip 库,现在我的套接字工作正常。

哇..!