Echo Client with UTF8 Encoding : Socket Client : Network C# Examples


C# Examples » Network » Socket Client »

 

Echo Client with UTF8 Encoding









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

class  MainClass
{
    const  int  echoPort  =  7;

    [STAThread]
    static  void  Main(  string[]  args  )
    {
        Socket  s  =  new  Socket(  AddressFamily.InterNetwork,  
            SocketType.Stream,  
            ProtocolType.Tcp  );
        s.Connect(  new  IPEndPoint(  IPAddress.Loopback,  echoPort  )  );

        UTF8Encoding  enc  =  new  UTF8Encoding();
        s.Send(  enc.GetBytes(  "test  message"  )  );
        Byte[]  buff  =  new  Byte[  1024  ];
        s.Receive(  buff  );
        System.Console.WriteLine(  enc.GetString(  buff  )  );
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Network
» Socket Client