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.

How to subscribe events onClose, onConnect, onError in websocket ?

See original GitHub issue

I can only subscribe to the message event

            webSocket("api") {
                incoming.consumeEach { frame ->
                    when (frame) {
                        is Frame.Close -> println("close") // not work
                        is Frame.Binary -> {
                            val length = frame.buffer.remaining()
                            val byteArray = ByteArray(length)
                            frame.buffer.get(byteArray)
                            val request = Mapper.mapTo<Request<Any>>(byteArray)
                        }
                    }
                }
            }

Such an opportunity will be in the future?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
cy6erGn0mcommented, Oct 18, 2018
  • onConnect: makes no sense as user’s block is only invoked when connected
  • onClose: incoming channel simply gets closed, a close reason could be obtained from closeReason deferred
  • onError: incoming channel gets closed with error (attempt to receive on this channel will cause it to throw an exception) and/or closeReason could be completed with the reason
2reactions
cy6erGn0mcommented, Oct 18, 2018

@soywiz Since this approach looks different too the classic approach we probably can add a small notice at our page http://ktor.io/servers/features/websockets.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get access to onclose event codes in Javascript ...
Try this: function onClose(event) { alert('Onclose called' + event); alert('code is' + event.code); alert('reason is ' + event.reason); alert('wasClean is' ...
Read more >
WebSockets - Events & Actions - Tutorialspoint
Close event marks the end of the communication between server and the client. Closing the connection is possible with the help of onclose...
Read more >
WebSocket - The Modern JavaScript Tutorial
There are totally 4 events: open – connection established,; message – data received,; error – websocket error,; close – connection closed.
Read more >
WebSocket: close event - Web APIs - MDN Web Docs
The close event is fired when a connection with a WebSocket is closed. Syntax. Use the event name in methods like addEventListener() ,...
Read more >
Using WebSockets - Quarkus
Because it's the canonical web socket application, we are going to create a simple chat ... session); } @OnClose public void onClose(Session session, ......
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