WrathChaos / StompClientLib

Simple STOMP Client library, Swift 3 and 4, 4.2, 5 compatible
https://www.freakycoder.com
MIT License
153 stars 81 forks source link

How I can ping server? #87

Closed Vlada31R closed 4 years ago

Vlada31R commented 4 years ago

Hi, help me please. Using socketClient.socket?.send("\n") fails. I need to ping the server because I get "Stream and encountered" error, even after setting heart-beat.

WrathChaos commented 4 years ago

Hello @Vlada31R, You cannot directly ping the server with this library but of course, you can use the connection methods to get the ping from server. I believe that you don't need to ping the server for your use-case, you have the Steam and encountered error only.

Did you check these issues?

26 , #17

Also, I'm planning to add the ping the server functionality soon.

Vlada31R commented 4 years ago

Hi, thank you for quick response. Yeah, I checked the issues. There are several possible solutions were mentioned:

  1. I can add heart-beat header - I did it, but it didn't help
  2. Put a timer for every 30s to send a ping command to server - but I have a question how to do it
  3. there also was solution to call openSocketWithURLRequest with timer for every 20 seconds - but I think that it's not very good idea to open connection each 20 sec, reconnection sounds better, but I also faced some troubles while trying to reconnect
  4. As for this point "control the stompclient connection when changing the new ViewController or any kinds of stuff" - I am using a singleton instance of a web sockets controller
  5. I also believe that it's not server problem because web client works okay That's why I decided to ping server directly. Maybe you have other ideas?
Vlada31R commented 4 years ago

@WrathChaos and maybe there are other opportunities to ping server with your library?

WrathChaos commented 4 years ago

Hello @Vlada31R, Sorry for the late response. Actually you can fork the library and open a PR to finish this one: https://github.com/WrathChaos/StompClientLib/pull/25 Then we can fix the ping server problem at all. Really sorry but I have literally no time to integrate this logic and test it. I'm always open to any contribution. If you have time, please complete this PR :) I'm happy to merge it.

Vlada31R commented 4 years ago

Hi, I see, thank you.

WrathChaos commented 4 years ago

I will try to add this feature in this weekend but I cannot promise you @Vlada31R

Vlada31R commented 4 years ago

Okay, thanks, I will try to do it. And I have one more assumption about the reason of "Stream and encountered" error. Could it be caused by using wss protocol? Thank you in advance!

WrathChaos commented 4 years ago

@Vlada31R, Library itself uses the Facebook's SocketRocket which means it uses a WebSocket. Therefore, you have to use wss protocol. Honestly, I have no idea if you can use it without wss protocol or not.

Vlada31R commented 4 years ago

I see, thank you very much!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.