question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a WsSession#id or provide a way to set one

See original GitHub issue

The way to track a WsSession feels a bit too primitive. Essentially you have to put the WsSession into a Map<WsSession, UUID> in order to do stuff like on disconnect of the socket perform cleanup of resources that may have been created during the session (keyed by incoming connection).

fun main(args: Array<String>) {
  val app = Javalin.create().port(7000)

  val connectionCount = AtomicInteger(0)
  val connected = hashMapOf<WsSession, UUID>()

  app.ws("/ws") { ws ->
    
    ws.onConnect { sess ->
      sess.idleTimeout = Duration.ofSeconds(5).toMillis()

      val clientId = UUID.randomUUID()
      val currentConnectionCount = connectionCount.incrementAndGet()
      connected += Pair(sess, clientId)

      logger.info("connection established 'client = {}'", clientId)
      logger.info("connection 'count = {}'", currentConnectionCount)
    }

    ws.onClose { sess, code, reason ->
      val currentConnectionCount = connectionCount.decrementAndGet()
      val clientId = connected[sess]

      // Imagine some cleanup logic here for the particular client. without a tracked ID that is impossible. 

      logger.info("connection closed 'client = {}', 'code = {}' 'reason = {}'", clientId, code, reason)
      logger.info("connection 'count = {}'", currentConnectionCount)
    }
  }

  app.start()
}

Possibly related to GH-104

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
plombardi89commented, Feb 1, 2018

Opened GH-120 to track dev progress

0reactions
tipsycommented, Feb 2, 2018

Closed by #120

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set a session id in Postman - Stack Overflow
In Postman native app: Turn on the Interceptor. Go to Headers; Key: Cookie; Value : sessionid=omuxrmt33mnetsfirxi2sdsfh4j1c2kv.
Read more >
Can not run sample Thingworx java sdk code - PTC Community
I am trying to run code provide from https://developer.thingworx.com/en/resources/guides/thingworx-java-sdk-tutorial put threads are ...
Read more >
set session id to socket in nodejs - gists · GitHub
set session id to socket in nodejs. GitHub Gist: instantly share code, ... sessionID.js ... app.use(express.static(path.join(__dirname, '/../public')));.
Read more >
B4J Question webapp help - B4X Programming Forum
Hi i have this code to access to a particular webpage passing a paramiter but i'm not able to set session attribute to...
Read more >
Managing Sessions With the Amazon Lex API
When you make a request, the session is identified by a combination of ... You can also use the PutSession operation to change...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found