Delegate StompClientDidConnect not called after connect->disconnect->connect
starlight173 opened this issue ยท 45 comments
var client = StompClientLib()
func establishConnection() {
if let urlComponents = self.urlComponents, let url = urlComponents.url {
client.openSocketWithURLRequest(request: NSURLRequest(url: url) , delegate: self)
}
}
func closeConnection() {
client.disconnect()
}
func stompClientDidConnect(client: StompClientLib!) {
Logger.log(message: "StompClientDidConnect", event: .d)
let topic = "/user/queue/notifications"
Logger.log(message: "Subscribe to topic: \(topic)", event: .d)
client.subscribe(destination: topic)
}
That delegate not even called when I try to reconnect. Please tell me how to fix this? Thank you.
Hello @gloryluu,
Can you check that did "stompClientDidDisconnect" delegate is called after you disconnect the socket? If it is not called then please check your disconnect method :)
Please give me feedback,
Have fun!
Yes it did.
Make some debug, I notice that after I call the method 'closeConnection', when I tried to reconnect, in file StompCLientLib, in the method 'openSocketWithURLRequest' the client is not NULL and the socket?.readyState is not CLOSED. So it never come inside.
@gloryluu I'm gonna check when I have time, let me some days :)
Hello, I had the same problem in my fork (I'm building a nativescript plugin with it and I had to do some changes) and I've solved in this way:
public func disconnect() {
if socket != nil {
connection = false
var headerToSend = [String: String]()
headerToSend[StompCommands.commandDisconnect] = String(Int(NSDate().timeIntervalSince1970))
sendFrame(command: StompCommands.commandDisconnect, header: headerToSend, body: nil)
socket!.close()
socket!.delegate = nil
socket = nil
}
}
basically I close the socket, nil the delegate and then nil the socket itself (so it will be recreated).
Hope this help
Dem
@gloryluu @demetrio812 Thank you so much for this contribution. I've added this to new version. Also, autoreconnect feature is going to be in this version after the tests are done :)
Hello guys,
New version is alive, 1.2.5, please try it and give me a feedback about this issue :) For now, I closed this issue.
Have fun
hi @WrathChaos
thanks for this awsome library
did you fix this problem?
Hello @Mahdimm,
Yes, it should be fixed on new version. If you still have problem, please give me a feedback about it and we can solve it together :)
Have fun
thanks of replying @WrathChaos
first time we connect its ok and if we try to disconnect also it works but readyState of socket property in StompClient object doesn't change to .CLOSED and it is still .OPEN, thus when we try to connect socket for second time it could not register. what should we do now?
@Mahdimm
Does it still a problem on 1.2.5 version? Also, have you tried auto reconnect or auto disconnect features together? I tried them at the same time for testing disconnect and reconnect issues and it was working well.
@WrathChaos
Yes, I work with 1.2.5 version.
Do you means that there are functions autoReconnect and autoDisconnect? because I could not find them!
At first, I used this function for register Socket :
func registerSocket( _ token:String ){
let baseURL = "ws://MYIPADDRESS:5050/stomp"
let completedWSURL = "\(baseURL)?access_token=\(token)"
let url = NSURL(string: completedWSURL)!
socketClient.openSocketWithURLRequest(request: NSURLRequest(url: url as URL) , delegate: self as StompClientLibDelegate)
}
and the use this function for disconnect:
socketClient.disconnect()
and for the second time use registerSocket() function to connect with new token but it could not register, for that reason I mentioned before!
@Mahdimm Let me test fast. While I'm testing, can you please try to use reconnect function. Here is the example of it :
// Reconnect after 4 sec
socketClient.reconnect(request: NSURLRequest(url: url as URL) , delegate: self as StompClientLibDelegate, time: 4.0)
@WrathChaos
I didn't see any function like reconnect
can you tell me the name of file?
thanks
@Mahdimm I guess you could not update the library itself.
Can you please delete the line of StompClientLib and pod install, then again write as :
pod StompClientLib
and again run pod install command on your terminal.
You can even check the new feature functions on ReadME file or StompClientLib in itself.
Also, I tried your use case on my test environment it works well. Please give me a feedback about your issue when you're done these steps :)
@WrathChaos
I did you're solution and version is 1.2.5 but we didn't found any function as you said.
look at this image:
this image
thanks
@Mahdimm
Working on it :)
@WrathChaos
Thanks
Im waiting for reply
Hello again @Mahdimm,
I don't know why but on my 1.2.5 version, could not get the new code base on the cocoapods. I just upgrade the new version as 1.2.7, it should be soon available. I will re-write when it is published.
Hey @Mahdimm,
Can you update the StompClientLib pod and try again? That was totally my mistake to did not update code base. Sorry :)
Hey @WrathChaos ,
Thanks for your response, yes it was updated successfully to 1.2.7 version, and reconnect function is available; But now when I want use openSocketWithURLRequest() my up crashed!
This image
Hello @MrShafiee,
Let's figure out what your problem is. I cannot understand what the error is with that image, can you post the console error?
Hello @WrathChaos ,
There is not any error on console log, I got it on simulator, but every thing is okey on real device.
and I have another question, is there any delegate function notify us when we subscribe on any destination?
Thanks.
There is no feature for subscrition delegate method but it is the first feature is going to work on it. It will be available soon :) I'm working on it.
Do you have any problem?
Hey @Mahdimm,
Unfortunately, I did not have time to add these delegates but this feature is the first place to do.
I will add them for the next update and it is going to be available within a week.
Also, PR is always welcome :)
@WrathChaos should the StompClientDidConnect delegate be called on connect/reconnect using autoreconnect method? (it is not for me)
Another question - is it possible to get following delegate somehow? - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
Getting just call to stompClientDidDisconnect(client:) delegate in that case.
Hi @deni2s,
Which version of the library are you using? (For the first question)
I am going to work on the new delegate methods ASAP. Still trying to make time for working on it.
@WrathChaos I am using the latest version.
@deni2s
Can you try the example? Every delegate is working with the example on my side. Each time auto-reconnect and disconnect. Its delegate gives me the console.log
Hey @WrathChaos, thanks for this library, I try to use this, but unfortunately, none of the delegate is calling on my end. Not sure what I am missing!! I can see the log "WebSocket is connected" from the library, but my delegate method func stompClientDidConnect(client: StompClientLib!)
is not calling. Did I need to add anything else?
@WrathChaos couldn't get the Example to work at all, looks like pod file is outdated (no target platform defined, no minimum ios version defined).
@gsathish02 and @deni2s , I'm working on it. I'm going to fix it tonight.
Sorry guys could not make time for it. Before this weekend I will fix it.
Hey guys @gsathish02 and @deni2s,
I've tested with my spring boot server. It totally works. I've used Java 8 on MacOS. Can you provide me with a test link?
Also, I've closed this issue, please re-open for your issues and let's continue on there.
Hello, I have save issue,
When I run example project it work as expected,
But if I create new project and copy/paste same code, delegate method stompClientDidConnect not called.
@xaeroolj Let's continue on your issue, please :)
Hello. I have same problem too. I have log "WebSocket is connected", but delegate method stompClientDidConnect has called no where. Maybe it should be called in func webSocketDidOpen(_ webSocket: SRWebSocket!), where is print "WebSocket is connected"?
Hello @4egoshev, Can you tell me which version are you using?
I use 1.3.1 version
@4egoshev Can you try with the latest release, please? (Currently 1.3.5)
@WrathChaos sorry, but it does not solve my problem
@4egoshev Can you provide me with a simple example on a repo?
@WrathChaos sorry for waiting. I was so busy all last week. Do you know, it works good in simple example now. I think, maybe something wrong with our backend. Any way, thanks for your work!:+1: Good luck:slightly_smiling_face:
@4egoshev Love to hear that, I hope you can make it work. Have fun :)