Websocket API server side Ping/Pong

0

Hi,

Does Websocket API do Ping/Pong on the server side to detect if a client is still connected? I find when the network on the client is switched off, Websocket API Gateway still thinks the connection is open until the idle timeout.

Lu

gefragt vor 5 Jahren6110 Aufrufe
7 Antworten
1

API Gateway WebSocket API does not perform server-side ping but it does respond with pong for the client side ping.

AWS
beantwortet vor 5 Jahren
  • Still no server-side ping? It would be great if you can implement it and trigger the disconnect route when the server-side ping fails.

0

I do not see any documentation where the RFC-compliant ping/pong mechanism of Websocket is supported. Can you point to this? In my experimentation, there is no "pong" response to a websocket "ping" without explicitly coding the integration back-end to respond. Your post suggests that API Gateway will handle client pings without requiring a user-defined integration handle this.

beantwortet vor 4 Jahren
0

I'm not sure how you experimented it, but I tested with wscat successfully.

wscat -c wss://***.execute-api.***.amazonaws.com/*** --slash
connected (press CTRL+C to quit)
'> /ping
< Received pong
'> ⏎

Edited by: jwaataws on Oct 31, 2020 10:13 AM

AWS
beantwortet vor 4 Jahren
0

I use wscat 4.0.1 to connect to API GW for Websocket but nothing happens (in wscat) when sending "/ping"

~ wscat -c wss://***.execute-api.eu-west-1.amazonaws.com/ --slash
Connected (press CTRL+C to quit)
~ /ping
~

What works:

  • Typing /close closes the connection.
  • Sending a message that does not start with "/" triggers the default route in API GW as expected.

But /ping ... nothing?

Edited by: andreasi77 on Jan 11, 2021 5:02 AM

Edited by: andreasi77 on Jan 11, 2021 7:37 AM

Edited by: andreasi77 on Jan 11, 2021 7:39 AM

beantwortet vor 3 Jahren
0

Answering myself since I (with help from AWS) found the solution.

API Gateway Websocket support clients sending ping control frame that defined in RFC doc. The client can send a ping frame to check the connection without any cost.
While API Gateway doesn't perform periodic server-side pings to connected clients, it does respond with pongs for the client-side pings. This is because that RFC dictates that servers MAY send out periodic pings, but that servers MUST respond with the appropriate control frames if pinged.

The reason for "< Received pong" not being printed when using wscat to send "/ping" to server was caused by a missing flag
"-P, --show-ping-pong print a notification when a ping or pong is received"

So the correct command to use is:
~ wscat -c wss://***.execute-api.eu-west-1.amazonaws.com/ --slash -P

beantwortet vor 3 Jahren
0

Thanks andreasi77!
Just tried it out on the command line with wscat and got a pong reply from the established connection. But still - I wonder how that would be used in my frontend javascript / VueJS app. I'm confused when trying to get an idea on how that would be sent and received. Is this being done in the background by the browser on intervals ( but not visible in the developer console network message panel? - I use the Chrome DevTools to monitor stuff in the console). Any insights is much appreciated!

beantwortet vor 3 Jahren
0

I am stuck at the same point - this is closest I have seen as it seems the browsers implementations of WS do not support ping control frames natively

https://stackoverflow.com/questions/26971026/handling-connection-loss-with-websockets/39765960#39765960

beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen