Add a WsSession#id or provide a way to set one
See original GitHub issueThe 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:
- Created 6 years ago
- Comments:9 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Opened GH-120 to track dev progress
Closed by #120