This article code just to be able to deeply understand the network communication, without the code back out, only need to understand, can change on the line
First you need to create a socket
Note the need to write in VS2010: New Socket (AddressFamily.InterNetwork, SocketType.Stream, protocoltype.tcp);
Socket socket = new socket (SocketType.Stream, protocoltype.tcp),//tcp, UDP.
Socket. Connect (new Dnsendpoint ("127.0.0.1", 8080));//Connect to the server. The default port number for the HTTP protocol is 80. Each server software listens to a port (other software can not listen to this port), the data sent to this port will only be received by this server software.
using (NetworkStream NetStream = new NetworkStream (socket))//read/write the stream of socket communication data
using (StreamWriter writer = new StreamWriter (NetStream))
{
Writer. WriteLine ("get/index.html http/1.1");//Enter each line of instructions
Writer. WriteLine ("host:127.0.0.1:8080");
Writer. WriteLine ();//empty line carriage return, indicating end of instruction
}
using (NetworkStream NetStream = new NetworkStream (socket))
using (StreamReader reader = new StreamReader (NetStream))
{
String line;
while (line = reader. ReadLine ())!=null)
{
Console.WriteLine (line);
}
}
Socket. Disconnect (FALSE);
Console Browser Code Combat