every connection to web server need a open port(default 80), so is it correct by regarding "http is based on socket"
or can I understand by this "TCP is a protocol, Socket implemented TCP, HTTP is based on TCP, so HTTP is based on Socket"?
HTTP is an application protocol, Socket is an operating system API. This means HTTP can not be based on sockets the same as cars are not based on gasoline.
Relationship between Socket and HTTP:
Sockets can be used to implement a HTTP server/client since sockets can be used to implement any kind of TCP server/client and HTTP is an application layer protocol on top of TCP.
But note that sockets are not essential to implement HTTP, i.e. you could use any other kind of API which manages to send network packets to implement it.
Related
We often hear about this saying:
Socket is a wrapper around the TCP/IP protocol.
but can make it more clarity? is Socket wrapper TCP/IP's transport layer? or every layer except application layer.
The Socket-interface is more like an API for various Internet and IPC protocols.
It is not really a protocol layer, but in implementation level, it may be used between layers.
For example, a HTTP client may use Socket-API for opening TCP connections to HTTP servers.
In the example the TCP is the transpont layer protocol. Usually TCP uses IP as network layer protocol. And HTTP is the protocol on top of TCP.
The Socket-interface uses term 'socket' for protocol end-points.
In many systems, a file descriptor type that is created by using socket() or accept() functions is called a 'socket'.
Hi guys I'm new to understanding protocols used over the web and need some help in understanding the basics of websockets,TCP/IP and HTTP.
My understanding of the relation between TCP/IP and HTTP is that IP is required to connect all networks. TCP is a mechanism that allows us to transfer data safely and HTTP, which utilizes TCP to transfer its data, is a specific protocol used by Web servers and clients.
Does this mean you can't send a HTTP request without TCP?
Websockets communicate using TCP layer and a connection between client and server is established through HTTP which is known as the handshake process.
Does websockets have its own protocol? How can you send a http request(hand shake process) to establish TCP/IP when you need TCP to carry out an HTTP request. I know I am missing something really important here and would be great to get my understanding of these protocols sharpened!
Firstly, IP is not necessarily required to connect all networks. However, it is the most widely used and adopted today (For now that is). Old network protocols such as Appletalk, IPX, and DECNet are all legacy network protocols that are not much used anymore, however they are still around to an extent. Don't forget IPv6 is out there as well, in some places, and can ride over IPv4 networks if your configuration is done properly.
When you say TCP being "safe", I would give it another word, and that would be intelligent. TCP is a transport protocol, and is the header that comes directly after the IPv4 header. TCP is primarily used for flow control and has become very efficient at error recovery in case a part of a packet or packets has been last when transferring/receiving. While this is great for some transactions, the error control requires an additional amount of overhead in the packet. Some applications, let's say VoIP for example, is very sensitive to delay, jitter (Variation in delay) and congestion. This is why it uses UDP.
Like TCP, UDP is a transport protocol, however there is no flow control. Think of it this way: When sending packets over TCP, it's like asking the other end if they received your message. If they did, they will acknowledge it. If not, you now have to determine how you will resend this information. UDP has none of this. You send your message to the other side, and hope it gets there.
Now if you want to talk about "safe" protocols, this is usually done at either the network layer (IPSec) or the application layer (SSL). Safe typically means secured.
A usual TCP three-way handshake looks like this:
Whoever sends the SYN is the client. Whoever receives that initial SYN is the server.
Client sends SYN --> Server
Now, if the server is listening, and/or there's not a firewall blocking the service (Which in that case you'd receive a TCP frame from the server with the RST,ACK bits set most likely), the server will respond with a SYN-ACK:
Server sends SYN/ACK --> Client
If the client received this packet, he will acknowledge he received it. This completes the three-way handshake and these two may begin exchanging information.
Client sends ACK --> Server
Here's a good site for some info:
http://www.tcpipguide.com/free/index.htm
What is the difference between socket programming and Http programming? can anyone help please?
HTTP is an application protocol. It basically means that HTTP itself can't be used to transport information to/from a remote end point. Instead it relies on an underlying protocol which in HTTP's case is TCP.
You can read more about OSI layers if you are interested.
Sockets on the other hand are an API that most operating systems provide to be able to talk with the network. The socket API supports different protocols from the transport layer and down.
That means that if you would like to use TCP you use sockets. But you can also use sockets to communicate using HTTP, but then you have to decode/encode messages according to the HTTP specification (RFC2616). Since that can be a huge task for most developers we also got ready clients in our developer frameworks (like .NET), for instance the WebClient or the HttpWebRequest classes.
With HTTP you use high-level HTTP protocol(that works on top of a socket). It's session-less which means you send text request like GET google.com and receive text or binary data in return, after that 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);
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();
}
With sockets you go on the 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});
HTTP Connection
HTTP connection is a protocol that runs on a socket.
HTTP connection is a higher-level abstraction of a network connection.
With HTTP connection the implementation takes care of all these higher-level details and simply send HTTP request (some header
information) and receive HTTP response from the server.
Socket Connection
Socket is used to transport data between systems. It simply connects two systems together, an IP address is the address of the
machine over an IP based network.
With socket connection you can design your own protocol for network connection between two systems.
With Socket connection you need to take care of all the lower-level details of a TCP/IP connection.
for two endpoints to be able to talk to each other they should both follow a set of rules. in computer these set of rules is called protocol.
for example for an endpoint like browser and for another like a web server they should both follow a set of rules or protocol called http to be able to communicate and trade information . so in the world wide web and this kind of communications only those who talk based on this http protocol could successfully talk to each other.
socket is just an endpoint. it could follow http protocol to come in a communication in www as a client requesting a page or it could act as a server listening to connections. or maybe it could follow another set of rules or protocols like ssh, ftp and communicate in other ways.
now in socket programming you could make a socket , bind it to an ip address and a port number to act as a port number and tell it to follow http , ssh ,ftp or whatever you want based on the communications that you want to use your socket for.
HTTP programming or HTTP request is used for loosely coupling and platform-neutral language technology communication where as socket programming is used where system has language specification protocol
Socket programming is a kind of middleware, residing between the application layer and the TCP layer. It's able to carry anything present in the application layer; even HTTP data.
It seems that many "connection" concept exist. such as socket connection, tcp connection and http connection.
so, what the difference?
They're different degrees of specialization: an HTTP connection is a type of TCP connection is a type of socket connection.
For two entities to communicate they need a hook to each other to pass messages across - These hooks are sockets. We can say they are identities of the process. Communication b/w these sockets would be over a socket connection.
Now, how does one send messages and receive messages? Who decides to open a connection request to a socket, how does one close. Many questions arise isn't? Here comes the your TCP. By following the rules put forth by TCP, applications engage in a message exchange using TCP protocol over the sockets. Now you can refer to them as TCP connection.
Now, it need not be just stream of data bytes that the two applications exchange using the TCP protocol and b/w the two sockets. Applications can define their own protocol - Like - I am looking for a content - do you have it? - Yes, here it is. One such applications defined protocol is HTTP. The web page of SO that you used your browser to read is over HTTP- TCP - and two sockets belonging to SO server and your browser.
What is the difference between socket programming and Http programming? can anyone help please?
HTTP is an application protocol. It basically means that HTTP itself can't be used to transport information to/from a remote end point. Instead it relies on an underlying protocol which in HTTP's case is TCP.
You can read more about OSI layers if you are interested.
Sockets on the other hand are an API that most operating systems provide to be able to talk with the network. The socket API supports different protocols from the transport layer and down.
That means that if you would like to use TCP you use sockets. But you can also use sockets to communicate using HTTP, but then you have to decode/encode messages according to the HTTP specification (RFC2616). Since that can be a huge task for most developers we also got ready clients in our developer frameworks (like .NET), for instance the WebClient or the HttpWebRequest classes.
With HTTP you use high-level HTTP protocol(that works on top of a socket). It's session-less which means you send text request like GET google.com and receive text or binary data in return, after that 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);
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();
}
With sockets you go on the 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});
HTTP Connection
HTTP connection is a protocol that runs on a socket.
HTTP connection is a higher-level abstraction of a network connection.
With HTTP connection the implementation takes care of all these higher-level details and simply send HTTP request (some header
information) and receive HTTP response from the server.
Socket Connection
Socket is used to transport data between systems. It simply connects two systems together, an IP address is the address of the
machine over an IP based network.
With socket connection you can design your own protocol for network connection between two systems.
With Socket connection you need to take care of all the lower-level details of a TCP/IP connection.
for two endpoints to be able to talk to each other they should both follow a set of rules. in computer these set of rules is called protocol.
for example for an endpoint like browser and for another like a web server they should both follow a set of rules or protocol called http to be able to communicate and trade information . so in the world wide web and this kind of communications only those who talk based on this http protocol could successfully talk to each other.
socket is just an endpoint. it could follow http protocol to come in a communication in www as a client requesting a page or it could act as a server listening to connections. or maybe it could follow another set of rules or protocols like ssh, ftp and communicate in other ways.
now in socket programming you could make a socket , bind it to an ip address and a port number to act as a port number and tell it to follow http , ssh ,ftp or whatever you want based on the communications that you want to use your socket for.
HTTP programming or HTTP request is used for loosely coupling and platform-neutral language technology communication where as socket programming is used where system has language specification protocol
Socket programming is a kind of middleware, residing between the application layer and the TCP layer. It's able to carry anything present in the application layer; even HTTP data.