简体   繁体   English

Websockets 只收到 PONG 响应

[英]Websockets only PONG responses are received

I have implemented SocketRocket for websocket communication in my app but as this library is too old and archived for now, we decided to implement StarScream which seems to be trustable.我已经在我的应用程序中实现了用于websocket通信的 SocketRocket,但是由于这个库太旧并且现在已存档,我们决定实现似乎是可信赖的StarScream

However, after my migration from SocketRocket => StarScream , I found that only PONG responses are received for my websockets and other requests are not being responded.但是,在我从SocketRocket => StarScream迁移之后,我发现我的 websocket 只收到了PONG响应,而其他请求没有得到响应。

Would anyone help me here find the issue or correct me?有人会在这里帮我找到问题或纠正我吗?

Here is my SocketRocket implementation where my websockets are working fine even in current live production app.这是我的SocketRocket 实现,即使在当前的实时生产应用程序中,我的 websocket 也可以正常工作。

Here is my StarScream implementation which is not working even with Production configuration, I use same production configs for both apps but SocketRocket works while StarScream fails.这是我的StarScream 实现,即使使用生产配置也无法工作,我对两个应用程序使用相同的生产配置,但 SocketRocket 在 StarScream 失败时工作。

If you check code, you will see lot of similarity with both implementation, even though I am not receiving proper response for StarScream implementation.如果你检查代码,你会发现这两个实现有很多相似之处,即使我没有收到对 StarScream 实现的正确响应。 I try to send ping requests every 2 seconds for which I get PONG response but I also do send auth request once socket is connected for which I never get any response while in SocketRocket I do get response for auth request.我尝试每 2 秒发送一次 ping 请求以获取PONG响应,但我也会在连接套接字后发送auth请求,但在 SocketRocket 中我从未收到任何响应,但我确实收到了身份验证请求的响应。

  • connectSocket() is the function where sockets are being created. connectSocket() 是正在创建 sockets 的 function。 Please ignore connectQuickStashSocket() for now as I have commented it temporarily.请暂时忽略 connectQuickStashSocket(),因为我已经暂时评论了它。

  • sendPing() is also omitted for now as I have to check response for auth, so, commented sendPing() call for every 2 seconds. sendPing() 现在也被省略了,因为我必须检查 auth 的响应,因此,每 2 秒注释一次 sendPing() 调用。

  • send() is the main function where writing data on socket takes place and I also get completion callback once data is written, still I don't get any response. send() 是主要的 function 发生在套接字上写入数据的地方,一旦写入数据,我也会收到完成回调,但我仍然没有得到任何响应。

NOTE: Commenting/uncommenting sendPing() , connectQuickStashSocket() will not change the response and the code behaves same.注意:评论/取消评论sendPing()connectQuickStashSocket()不会改变响应和代码行为相同。

Here I am attaching logs for SocketRocket where you will see all request/response working fine:在这里,我附上了 SocketRocket 的日志,您将在其中看到所有请求/响应工作正常:

>>>> 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

Here is logs for StarScream where only PONG is received and response for auth request is not received, it only shows data written as request:这是 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

Please suggest me here what I can do and how to track what is the actual problem.请在这里建议我我能做什么以及如何跟踪实际问题。

I was facing different error which I got to know once I setup dev environment on my local machine and connected websockets over there.我遇到了不同的错误,一旦我在本地机器上设置了开发环境并在那里连接了 websockets,我就知道了。

I checked logs from server and got that it was giving me zlib - gzip: invalid header .我检查了服务器的日志,发现它给了我zlib - gzip: invalid header

So, the issue was that server not sending any response as it was not getting the request in proper format.因此,问题在于服务器没有发送任何响应,因为它没有以正确的格式获取请求。

I updated gzip library via POD and now my sockets are working perfect.我通过 POD 更新了 gzip 库,现在我的 sockets 运行良好。

Whew..!呼……!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM