Skip to content

How do I know whether to use receive_text or receive_bytes? #52

Answered by frankie567
WSH032 asked this question in Q&A
Discussion options

You must be logged in to vote

Well, generally speaking, you know whether your WebSocket sends you a string or bytes; it's part of how it's implemented. So receive_bytes and receive_text are convenient shortcuts.

Obviously, for a proxy, you don't know in advance. Thus, the way you show with plain receive and check the nature of the message is the way to go. It's part of the API, it's documented: https://frankie567.github.io/httpx-ws/reference/httpx_ws/#httpx_ws.AsyncWebSocketSession.receive

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@WSH032
Comment options

Answer selected by WSH032
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants