简体   繁体   中英

Should client or server send ping message?

I always thought it's the responsibility of the client to send a ping message to make sure server is available or handle disconnection in a proper way.

But lately I read an article where the initiator of ping messages is server side. So, server sends ping and client should respond with pong if it can.

What's the more general universal approach and why?

I can't really answer the question as it probably depends on the case. But how can the server knows who send ping to if the client never sent anything before?

In my opinion it's the client who need to start the "conversation".

I see you mentionned websocket in tags. websocket (server) needs to receive a first message from the client before starting to send the expected data to this client.

According to the websocket RFC - examples , it shows Unmasked Ping request ( Ping frame) and masked Ping response ( Pong frame) where Ping is from server and Pong is from client.

But, Ping and Pong sections mention "endpoint" which can be either client or server.

So, client and server both should be able to send Ping frame and the other party should reply with Pong frame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM