Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate StompClientDidConnect not called after connect->disconnect->connect #15

Closed
starlight173 opened this issue Feb 1, 2018 · 45 comments
Assignees
Labels

Comments

@starlight173
Copy link

starlight173 commented Feb 1, 2018

	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.

@WrathChaos
Copy link
Owner

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!

@starlight173
Copy link
Author

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.

@WrathChaos
Copy link
Owner

@gloryluu I'm gonna check when I have time, let me some days :)

@WrathChaos WrathChaos self-assigned this Feb 1, 2018
@WrathChaos WrathChaos added the Bug label Feb 1, 2018
@demetrio812
Copy link

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

@WrathChaos
Copy link
Owner

@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 :)

@WrathChaos
Copy link
Owner

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

@Mahdimm
Copy link

Mahdimm commented Oct 23, 2018

hi @WrathChaos
thanks for this awsome library
did you fix this problem?

@WrathChaos
Copy link
Owner

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

@Mahdimm
Copy link

Mahdimm commented Oct 23, 2018

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?

@WrathChaos
Copy link
Owner

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

@Mahdimm
Copy link

Mahdimm commented Oct 23, 2018

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

@WrathChaos
Copy link
Owner

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

@Mahdimm
Copy link

Mahdimm commented Oct 23, 2018

@WrathChaos
I didn't see any function like reconnect
can you tell me the name of file?
thanks

@WrathChaos
Copy link
Owner

@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 :)

@Mahdimm
Copy link

Mahdimm commented Oct 23, 2018

@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

@WrathChaos
Copy link
Owner

@Mahdimm
Working on it :)

@Mahdimm
Copy link

Mahdimm commented Oct 23, 2018

@WrathChaos
Thanks
Im waiting for reply

@WrathChaos
Copy link
Owner

WrathChaos commented Oct 23, 2018

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.

@WrathChaos
Copy link
Owner

Hey @Mahdimm,
Can you update the StompClientLib pod and try again? That was totally my mistake to did not update code base. Sorry :)

@MrShafiee
Copy link

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

@WrathChaos WrathChaos reopened this Oct 24, 2018
@WrathChaos
Copy link
Owner

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?

@MrShafiee
Copy link

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.

@WrathChaos
Copy link
Owner

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?

@Mahdimm
Copy link

Mahdimm commented Nov 4, 2018

Hi @WrathChaos

did you add delegate for subscribe & unSubscribe?

thanks for supporting

@WrathChaos
Copy link
Owner

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

@deni2s
Copy link

deni2s commented Jun 7, 2019

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

@WrathChaos
Copy link
Owner

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.

@deni2s
Copy link

deni2s commented Jun 10, 2019

@WrathChaos I am using the latest version.

@WrathChaos
Copy link
Owner

@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

@gsathish02
Copy link

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?

@deni2s
Copy link

deni2s commented Jun 11, 2019

@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).

@WrathChaos
Copy link
Owner

@gsathish02 and @deni2s , I'm working on it. I'm going to fix it tonight.

@WrathChaos WrathChaos reopened this Jun 11, 2019
@WrathChaos
Copy link
Owner

Sorry guys could not make time for it. Before this weekend I will fix it.

@WrathChaos
Copy link
Owner

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?

@WrathChaos
Copy link
Owner

Also, I've closed this issue, please re-open for your issues and let's continue on there.

@xaeroolj
Copy link

xaeroolj commented Jul 9, 2019

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.

@WrathChaos
Copy link
Owner

@xaeroolj Let's continue on your issue, please :)

@dev-lis
Copy link

dev-lis commented Jul 28, 2019

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

@WrathChaos
Copy link
Owner

Hello @4egoshev, Can you tell me which version are you using?

@dev-lis
Copy link

dev-lis commented Jul 29, 2019

I use 1.3.1 version

@WrathChaos
Copy link
Owner

@4egoshev Can you try with the latest release, please? (Currently 1.3.5)

@dev-lis
Copy link

dev-lis commented Jul 29, 2019

@WrathChaos sorry, but it does not solve my problem

@WrathChaos
Copy link
Owner

@4egoshev Can you provide me with a simple example on a repo?

@dev-lis
Copy link

dev-lis commented Aug 7, 2019

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

@WrathChaos
Copy link
Owner

@4egoshev Love to hear that, I hope you can make it work. Have fun :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants