Use NetworkStream to write to a client : TcpListener : Network C# Examples


C# Examples » Network » TcpListener »

 

Use NetworkStream to write to a client









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

class  MainClass
{
    public  static  void  Main()  
    {
        TcpListener  tcpl  =  new  TcpListener(9999);
        tcpl.Start();

        for  (;;)
        {
            Socket  newSocket  =  tcpl.AcceptSocket();
            if  (newSocket.Connected)
            {
                NetworkStream  ns  =  new  NetworkStream(newSocket);

                byte[]  buf  =  {1,2,3,4,5,6,7,8,9};
                ns.Write(buf,  0,  9);

                ns.Flush();
                ns.Close();

            }
            newSocket.Close();
            break;

        }
    }

}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Network
» TcpListener