Use a NetworkStream to read from a server : TcpClient « Network « C# / CSharp Tutorial






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();

  }

}








33.7.TcpClient
33.7.1.Creating Socket Connections
33.7.2.Use a NetworkStream to read from a server
33.7.3.Create NetworkStream from TcpClient
33.7.4.use TcpClient to connect to a server
33.7.5.Create BinaryWriter and BinaryReader from TcpClient
33.7.6.Use TcpClient to write to/read from a server
33.7.7.Network Client and StreamReader
33.7.8.Network Client with TcpClient and NetworkStream
33.7.9.Write string to server
33.7.10.Read csv from finance.yahoo.com with TcpClient