简体   繁体   中英

WebSocketReceiveResult force to receive binary

I am using Websocket.Client which is a wrapper around ClientWebSocket , within its internals I can see WebSocketReceiveResult and it is using it to detect the message contents result.MessageType == WebSocketMessageType.Text .

Is there any way to force a web socker to only to receive binary messages (not do any conversion to string?), or is the data format specified by the server?

namespace Websocket.Client
{
    //
    // Summary:
    //     Received message, could be Text or Binary
    public class ResponseMessage
    {
        //
        // Summary:
        //     Received text message (only if type = WebSocketMessageType.Text)
        public string Text { get; }
        //
        // Summary:
        //     Received text message (only if type = WebSocketMessageType.Binary)
        public byte[] Binary { get; }
        //
        // Summary:
        //     Current message type (Text or Binary)
        public WebSocketMessageType MessageType { get; }

        //
        // Summary:
        //     Create binary response message
        public static ResponseMessage BinaryMessage(byte[] data);
        //
        // Summary:
        //     Create text response message
        public static ResponseMessage TextMessage(string data);
        //
        // Summary:
        //     Return string info about the message
        public override string ToString();
    }
}

This feature was implemented by the author of Websocket.Client within a few hours of posting on the github page... amazing!

using var client = new WebsocketClient()
{
   IsTextMessageConversionEnabled = false
};

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