.net WebSocket: CloseOutputAsync vs CloseAsync

前端 未结 1 1360
再見小時候
再見小時候 2021-02-19 21:18

We have a working ASP.NET Web API REST service that uses WebSockets on one of our controller\'s methods using HttpContext.AcceptWebSocketResponse(..).

The socket handl

相关标签:
1条回答
  • 2021-02-19 21:38

    https://www.salmanq.com/blog/5-things-you-probably-didnt-know-about-net-websockets/

    ...The graceful way is CloseAsync which when initiated sends a message to the connected party, and waits for acknowledgement. ...The other option is to use CloseOutputAsync this is more of a “fire-and-forget” approach. ...

    It looks like you're getting a closing message;

    if (result.MessageType == WebSocketMessageType.Close ||
                currentSocketState == WebSocketState.CloseReceived)
    

    so I'd say you'd be just fine using CloseOutputAsync because you've already gotten a message that says "I want to close this connection".

    0 讨论(0)
提交回复
热议问题