WebSockets in .NET Core

net 6 newbie 121 Reputation points
2024-09-28T04:24:04.84+00:00

The Client WebSocket Object has ReceiveAsync() method with two overloads.

One with ArraySegment<Byte> and other one is Memory<Byte>.

Which one to use under which scenarios with an example?

I have a requirement where I am sending smaller size data and receiveing large size data from the WebSocket.

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Bruce (SqlWork.com) 81,976 Reputation points Volunteer Moderator
    2024-09-28T15:49:15.65+00:00

    It depends on the code processing the data. ArraySegment() is used to get segments (span) of an existing array efficiently. Memory<> is just a span, but uses heap memory instead of stack memory.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.