What is difference between grpc and websocket? Which one is more suitable for bidirectional streaming connection?

前端 未结 2 1229
一整个雨季
一整个雨季 2021-01-30 01:09

I want to develop a client-server application in a bi-directional streaming manner.

what is more suitable technology for this, grpc or websocket?

2条回答
  •  醉酒成梦
    2021-01-30 01:51

    gRPC is an API/Protocol on top of HTTP/2, so it is more relevant to compare HTTP/2 and Websockets.

    Note: HTTP/2 Server Push is not relevant here either. That is a website optimization technique for cacheable (GET) resources.

    Websocket and HTTP/2 support binary data frames with low overhead (a few bytes), however frames (whole payload) in Websocket is masked at sender and then unmasked at receiver. See What is the mask in a WebSocket frame?.

    With HTTP/2 you can have multiple streams multiplexed over the same connection. This need to be handled by application developer or a library when using Websocket - if desired.

    If your client is a browser, the answer to HTTP/2 or Websockets for low latency client to server messages may be relevant.

提交回复
热议问题