stream does not support seeking?

mc 4,416 Reputation points
2023-11-10T09:29:58.99+00:00

I create socket and want to write data to the socket.

and I find the networkstream

NetworkStream stream =new NetworkStream(socket);

stream.AsRandomAccessStream() throws exception

how to get randomAccessStream from socket or networkStream?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,515 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. gekka 8,856 Reputation points MVP
    2023-11-11T03:59:10.2866667+00:00

    The remarks in NetworkStream include the following sentence.

    The NetworkStream does not support random access to the network

    If you want to use it, you can use AsInputStream or AsOutputStream instead of AsRandomAccessStream.

    1 person found this answer helpful.

  2. 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.

    5 deleted comments

    Comments have been turned off. Learn more

  3. Xiaopo Yang - MSFT 12,721 Reputation points Microsoft Vendor
    2023-11-13T02:04:26.8566667+00:00

    The network data stream does not support random access by design as @gekka answered. But you can copy it to a stream that does support random access for example MemoryStream. See the Example: Convert .NET Framework to Windows Runtime random-access stream.

    0 comments No comments

Your answer

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