Uses a TcpClient to handle HTTP : TCP Client « Network « C# / C Sharp






Uses a TcpClient to handle HTTP


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


public class TryTcp {
  public static void Main(String [] args) {
    TcpClient client = new TcpClient("www.java2s.com", 80);
    NetworkStream stream = client.GetStream();
    byte[] send = Encoding.ASCII.GetBytes("GET HTTP/1.0 \r\n\r\n");
    stream.Write(send, 0, send.Length);
    byte[] bytes = new byte[client.ReceiveBufferSize];
    int count = stream.Read(bytes, 0, (int)client.ReceiveBufferSize);
    String data = Encoding.ASCII.GetString(bytes);
    char[] unused = {(char)data[count]};
    Console.WriteLine(data.TrimEnd(unused));
    stream.Close();
    client.Close();
  }
}
           
       








Related examples in the same category

1.Network Stream Tcp Client
2.Simple Tcp Client
3.Var Tcp Client
4.Bad Tcp Client
5.Fixed Tcp Client
6.Stream Tcp Client
7.Employee Client
8.Network Order Client
9.Tcp Client Sample
10.Async Tcp ClientAsync Tcp Client
11.Select Tcp Client
12.Picky Tcp Client