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

7개 답변
1

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

AWS
답변함 5년 전
  • 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.

답변함 4년 전
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
답변함 4년 전
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

답변함 3년 전
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

답변함 3년 전
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!

답변함 3년 전
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

답변함 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠