Use a NetworkStream to read from a server : TcpClient : Network C# Examples


C# Examples » Network » TcpClient »

 

Use a NetworkStream to read from a server









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

class  MainClass
{
    public  static  void  Main()  
    {
        TcpClient  newSocket  =  new  TcpClient("localhost",  50001);

        NetworkStream  ns  =  newSocket.GetStream();

        byte[]  buf  =  new  byte[100];
        ns.Read(buf,  0,  100);

        char[]  buf2  =  new  char[100];
        for(int  i=0;i<100;i++)
            buf2[i]=(char)buf[i];
        Console.WriteLine(buf2);

        ns.Close();
        newSocket.Close();

    }

}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Network
» TcpClient