WebsocketStompKit icon indicating copy to clipboard operation
WebsocketStompKit copied to clipboard

Initial Connect message can not be sent due to WebsocketStompKit.socket not being connected

Open mixdux opened this issue 8 years ago • 6 comments

Hello guys, it's me again! After some recent debugging on the server side, we indirectly found out a slight omission that occurs during initial web socket connection process:

  1. After receiving 101 from server, websocketDidConnect:(JFRWebSocket*) socket method gets called
  2. sendFrameWithCommand:(NSString *)command... is then called and is supposed to send kCommandConnect message to server

The problem occurs within send method, more precisely:

if (![self.socket isConnected]) {
    return;
}

In small number of cases it happens that socket is indeed not connected and initial connection won't be made. Moreover, neither websocketDidDisconnect:(NSError *)error delegate method nor client's connectWithHeaders: method('s block) do not get called back. I had no definitive way of knowing whether connection is slow and super laggy or initial connection hasn't been made; so I added a call to websocketDidDisconnect:(NSError *)error with custom error which I further on handle by myself.

As I mentioned earlier, this happens in small number of cases but should be addressed since workarounds sometimes may omit a key library callback or function they are supposed to call. Cheers!

mixdux avatar Apr 04 '16 17:04 mixdux

Hi, I have the issuse like you, sometimes the socket can't intit. Did you fix this issuse?

thaoth58 avatar Oct 12 '16 03:10 thaoth58

Hello thaoth52, Yes, indeed I have - I have removed the return from inside it and swaped it with

NSError *customError = [[NSError alloc] initWithDomain:@"com.myCompany.randomName" code:100 userInfo:nil];
dispatch_async(dispatch_get_main_queue(), ^{
   [self websocketDidDisconnect:socket error: customError];
});
return;

After that, I am handling the error in the usual connectWithHeaders method of this library, because the error gets caught there. Try it, maybe you will find a more elegant way to handle this - I am checking whether the error that occurred is mine and try to reconnect after some time (5 seconds).

mixdux avatar Oct 12 '16 06:10 mixdux

You help me a lot. Thank so much 👍

thaoth58 avatar Oct 13 '16 02:10 thaoth58

There is one more issuse. I send connect request to server: ">>> CONNECT accept-version:1.2 heart-beat:5000,10000 host:103.200.20.191"


but it stops there, doesn't response anything more. It have to be: "<<< CONNECTED version:1.2 heart-beat:0,0"

Do you meet this issuse?

thaoth58 avatar Oct 13 '16 04:10 thaoth58

I can not be absolutely certain why it won't connect, but you can debug and follow whether your code sends/receives any additional messages to/from server by putting a breakpoint to receivedFrame: method. I have found several more patches for this library, but considering this problem with heartbeat, you can either turn it off by initialising your client with initWithURL:webSocketHeaders:useHeartbeat: and passing NO as the final parameter, or finding the variable called clientHeartBeat and setting values there (if you want, you can create an interface method on .h file since clientHeartBeat is safely locked inside the .m file, or change it directly in .m file if you don't want to adjust its value during the programs execution).

mixdux avatar Oct 14 '16 06:10 mixdux

Oh thank for your reply. There is an issuse with my server. It dosen't send anything after i request :D

thaoth58 avatar Oct 14 '16 06:10 thaoth58