In HTTP, you use the high-level HTTP protocol (which runs on top of the socket). It is session-independent, which means that you send a text request, for example GET google.com , and receive text or binary data in response, after which the connection is closed (in HTTP 1.1, persistent connections are available)
MSDN example:
public static void Main (string[] args) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]); HttpWebResponse response = (HttpWebResponse)request.GetResponse (); Console.WriteLine ("Content length is {0}", response.ContentLength); Console.WriteLine ("Content type is {0}", response.ContentType);
With sockets, you go one level lower and actually control the connection and send / receive raw bytes.
Example:
var remoteEndpoint=new IPEndPoint(IPAddress.Loopback, 2345); var socket = new Socket(remoteEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.Connect(remoteEndpoint); socket.Send(new byte[] {1, 2, 3, 4});
Anri Feb 27 '13 at 9:18 2013-02-27 09:18
source share