Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# networkstream read all bytes

// Examples for CanRead, Read, and DataAvailable. 
// Check to see if this NetworkStream is readable. 
if(myNetworkStream.CanRead)
{
    byte[] myReadBuffer = new byte[1024];
    StringBuilder myCompleteMessage = new StringBuilder();
    int numberOfBytesRead = 0;

    // Incoming message may be larger than the buffer size. 
    do{
         numberOfBytesRead = myNetworkStream.Read(myReadBuffer, 0, myReadBuffer.Length);

         myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));

    }
    while(myNetworkStream.DataAvailable);

    // Print out the received message to the console.
    Console.WriteLine("You received the following message : " +
                                 myCompleteMessage);
}
else
{
     Console.WriteLine("Sorry.  You cannot read from this NetworkStream.");
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# recorrer una lista 
Csharp :: c# streamreader to file 
Csharp :: C# checking if a value is a int 
Csharp :: c# unit test exception using try catch 
Csharp :: update a file where there is a keyword c# 
Csharp :: how to set the current user httpcontext.current.user asp.net -mvc 
Csharp :: BulkWrite c# example mongodb 
Csharp :: .net core copy file in folder to root 
Csharp :: asp.net call controller from another controller 
Csharp :: Palindromic substrings 
Csharp :: how to check if button is pressed unity 
Csharp :: c# interface properties 
Csharp :: unity GUI TextField enter 
Csharp :: c# how to make object rotate forever 
Csharp :: long string c# 
Csharp :: Get replace normal text from word document in C# 
Csharp :: How to execute script in C# 
Csharp :: change physics material unity 
Csharp :: c# arrays 
Csharp :: c# run a scheduled task 
Csharp :: static keyword 
Csharp :: assert.equal 
Csharp :: how to get the dynamic year for your web app in mvc 
Csharp :: dataannotations for currency in c# 
Csharp :: 1180 beecrowd URI 
Csharp :: blazor conditional reenreing 
Csharp :: Null check operator used on a null value 
Csharp :: Task timed out after 10.02 seconds 
Csharp :: c# get innermost exception 
Csharp :: asp.net list size 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =