Write to a NetworkStream : NetworkStream : Network C# Source Code


Custom Search

C# Source Code » Network » NetworkStream »

 

Write to a NetworkStream








    
 
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;


class Program {
    static void Main(string[] args) {
        TcpClient client = new TcpClient();
        IPHostEntry host = Dns.GetHostByName("www.google.com");
        client.Connect(host.AddressList[0], 8000);

        NetworkStream clientStream = client.GetStream();

        string request = "LIST";
        byte[] requestBuffer = Encoding.ASCII.GetBytes(request);
        clientStream.Write(requestBuffer, 0, requestBuffer.Length);

        byte[] responseBuffer = new byte[256];
        MemoryStream memStream = new MemoryStream();
        int bytesRead = 0;
        do {
            bytesRead = clientStream.Read(responseBuffer, 0, 256);
            memStream.Write(responseBuffer, 0, bytesRead);
        } while (bytesRead > 0);



    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Network
» NetworkStream