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


C# Examples » Network » TcpClient »

 

Use TcpClient to write to/read from a server









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

public  class  MainClass
{
        private  static  void  Main()
        {
                using  (TcpClient  client  =  new  TcpClient())
                {
                        Console.WriteLine("Attempting  to  connect  to  the  server  ","on  port  8000.");

                        client.Connect(IPAddress.Parse("127.0.0.1"),  8000);

                        using  (NetworkStream  networkStream  =  client.GetStream())
                        {
                                using  (BinaryWriter  writer  =  new  BinaryWriter(networkStream))
                                {
                                        writer.Write("info");

                                        using  (BinaryReader  reader  =  new  BinaryReader(networkStream))
                                        {
                                                Console.WriteLine(reader.ReadString());
                                        }
                                }
                        }
                }
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Network
» TcpClient