-2

i'm working on a project which i need to use Websocket to exchange data with server

and

i was wondering what is usage of ping and pong in Websocket and what are them?

Thanks

Alireza aj
  • 71
  • 1
  • 11

2 Answers2

1
Abbas Torabi
  • 245
  • 2
  • 13
  • thank you , but i wanna work with webSocket not socket.IO (i think they are diffrent .aren't they?). and could you briefly explain why should be use ping and pong ? how can they help us ? @Abbas Torabi – Alireza aj Feb 24 '19 at 15:19
  • @Alirezaaj yes there is difference between websocket & socket.io the difference is: Its advantages are that it simplifies the usage of WebSockets , and probably more importantly it provides failovers to other protocols in the event that WebSockets are not supported on the browser or server. & if you wanna use web socket use these librarys: https://github.com/daltoniam/Starscream https://github.com/tidwall/SwiftWebSocket – Abbas Torabi Feb 26 '19 at 07:44
  • @Alirezaaj for ping & pong actually WebSockets implement their own Ping/Pong semantics to keep the connection alive in the absence of any data being sent. This is something you typically have to account for with TCP sockets to ensure the other end hasn’t gone away. – Abbas Torabi Feb 26 '19 at 07:44
0

ping and pong is used for checking the websocket connection. in the way that if the client sends a ping to server and the server doesn't respond with a pong , the websocket is disconnected. It's also used to check the speed of data exchange between server and client.

A.sobhdel
  • 234
  • 4
  • 11