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

I am still receiving data after I stop the service of socket cluster #47

Open
aalap03 opened this issue Mar 7, 2019 · 0 comments
Open

Comments

@aalap03
Copy link

aalap03 commented Mar 7, 2019

I have socket cluster client setup as described in the documents. I start the service to listen the changes and stop it when I dont want to listen. My issue is after stopping the service as well I receive data. Either there is another way to stop listening or there is a bug in the library. I have posted the code here.

class SocketForSecurityAgents : IntentService(SocketForSecurityAgents::javaClass.name), BasicListener, AnkoLogger {

  override fun onCreate() {
    super.onCreate()
    info { "onCreate:" }
   
  }

override fun onHandleIntent(intent: Intent?) {
    info { "onHandleIntent socket: ${SERVER_URL + cobaltStore?.token}" }
    val socket = Socket(SERVER_URL + cobaltStore?.token)
    socket.setListener(this)
    socket.setReconnection(ReconnectStrategy().setDelay(2000).setMaxAttempts(30))
    socket.connect()

    channel = socket.createChannel(channelName)
    channel?.subscribe { name, error, data ->
        info { "Subscribe: name: $name" }
        info { "Subscribe: error: $error" }
        info { "Subscribe: data: $data" }
    }
    channel?.onMessage { name, data ->
        info { "name: $name" }
        info { "data: $data" }
   }
}
  override fun onDestroy() {
    super.onDestroy()
    info { "onDestroy" }
  }
}

In my fragmnet I start and stop this service like this.

context.startService(Intent(context, SocketForSecurityAgents::class.java)

context.stopService(Intent(context, SocketForSecurityAgents::class.java)

When service is running to listen from socket, it gives onCreate logs on starting, logs in between in onHandleInten method also I see onDestroy when I stop the service.

My issue is I still receive messages in onHandleIntent after destroying service. Please let me know how to stop listening to channel. These are the logs

2019-03-07 16:40:25.702 22928-22928/myApp I/SocketForSecurityAgents: onCreate:
        2019-03-07 16:40:25.703 22928-22928/myApp I/SocketForSecurityAgents: onCreate: channel localhost_SECURITY
        2019-03-07 16:40:25.724 22928-24605/myApp I/SocketForSecurityAgents: onHandleIntent sconnected tochannel 
        .
        . getting data as expected 
        .
        2019-03-07 16:40:26.024 22928-24607/myApp I/SocketForSecurityAgents: onConnected: socket io.github.sac.Socket@f5a82f6
    2019-03-07 16:40:26.049 22928-22928/myApp I/SocketForSecurityAgents: onDestroy
    2019-03-07 16:40:26.064 22928-24607/myApp I/SocketForSecurityAgents: Subscribe: still receiving
    2019-03-07 16:40:26.064 22928-24607/myApp I/SocketForSecurityAgents: Subscribe: 
    2019-03-07 16:40:26.065 22928-24607/myApp I/SocketForSecurityAgents: Subscribe: 
    2019-03-07 16:40:26.067 22928-24607/myApp I/SocketForSecurityAgents: onAuthentication: status: false
    2019-03-07 16:41:20.161 22928-23872/myApp I/SocketForSecurityAgents: name: .
    2019-03-07 16:41:20.161 22928-23912/myApp I/SocketForSecurityAgents: name: ... still receiving data
    2019-03-07 16:41:20.161 22928-24199/myApp I/SocketForSecurityAgents: name:
    2019-03-07 16:41:20.162 22928-24199/myApp I/SocketForSecurityAgents: data: 
    2019-03-07 16:41:20.162 22928-23912/myApp I/SocketForSecurityAgents: data: 
    2019-03-07 16:41:20.162 22928-23872/myApp I/SocketForSecurityAgents: data: 
    2019-03-07 16:41:20.163 22928-24607/myApp I/SocketForSecurityAgents: name: 
    2019-03-07 16:41:20.163 22928-24607/myApp I/SocketForSecurityAgents: data: 
    2019-03-07 16:41:20.410 22928-23872/myApp I/SocketForSecurityAgents: name: 
    2019-03-07 16:41:20.410 22928-23872/myApp I/SocketForSecurityAgents: data: 
    2019-03-07 16:41:20.413 22928-24199/myApp I/SocketForSecurityAgents: name: 
    2019-03-07 16:41:20.413 22928-24607/myApp I/SocketForSecurityAgents: name: 
    2019-03-07 16:41:20.413 22928-24199/myApp I/SocketForSecurityAgents: data: 
    2019-03-07 16:41:20.413 22928-24607/myApp I/SocketForSecurityAgents: data: 
    2019-03-07 16:41:20.420 22928-23912/myApp I/SocketForSecurityAgents: name: 
    2019-03-07 16:41:20.420 22928-23912/myApp I/SocketForSecurityAgents: data: 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant