Sockets are the ends of a communication between two processes (applications) through a network of computers. In the operating system these ends are resources that the system creates upon request of the processes so that they can communicate over the network. As today most communication between computers is based on Internet Protocol, most of the sockets sane internet sockets. From the programmer’s point of view they are accessed through an API (from the operating system or indirectly through a library) that makes it possible to establish communication with a "socket address" (a unique combination of an IP address and a port number).
Two types of socket are more common, the stream sockets (that underneath the cloths use the TCP protocol in the transport layer, so I usually call them TCP sockets) and the Datagram sockets (which use the UDP protocol). The difference between them is that the TCP sockets keep the connection to the other side open throughout the communication and ensure the arrival of the data (bytes) in the sequence in which they were sent. Already the UDP sockets do not establish connection, only "play" a data packet in the network and do not guarantee that this data reaches the other side nor that its order is respected.
With sockets you can implement inter-process communication or even a higher-level protocol (called an application protocol, due to the layer it is located in ISO/OSI model) which other developers may use, such as HTTP itself or Websocket, implementing protocols implemented on TCP sockets.
Since HTTP follows a well-defined sequence of steps (opening the connection, requesting, receiving the response, and closing the connection), it usually gives the impression of not being persistent. But underneath the scenes he’s running these steps on persistent communication, allowed by TCP. There are techniques that keep the HTTP connection open for a long time for persistent data transmission (see Comet). Are "".
However, a more appropriate way to keep an open connection between Javascript browsers for real-time data exchange is the comparatively new Websocket protocol. It is an application protocol, also based on TCP, that can be implemented by web servers and served on the same port as HTTP (port 80). HTTP has been relatively well thought out and allows this "migration" from one application protocol to another, after a Handshake initial at HTTP.
It can be concluded that, despite the similarity of the names, they are different concepts. Websocket is an application-to-application communication protocol (browsers), which beneath the screens has its data carried by the TCP protocol, which in turn bridges the gap between two sockets (operating system concept). In other words, Websocket uses sockets.
I have exactly the same question. I used HTML5’s Websocket, created a chat, but still, I don’t know exactly differentiate the definitions (regarding concepts and such)
– Wallace Maxters