Network Socket

What is a Network Socket?

A network socket is an internal endpoint for sending or receiving data within a node on a computer network (Wikipedia).
-------------------------

You are using sockets when you download a pdf file or when whatsapp connects to its server, you are using network sockets all the time. Network sockets are used to transport information to/from a remote end point. So, you could say from previous posts, what's the difference with HTTP?

HTTP is an application protocol. It basically means that HTTP itself can't be used to transport information to/from a remote end point. ... The socket API supports different protocols from the transport layer and down.

 For example, in a connection between 10.20.30.40:4444 and 50.60.70.80:8888 (local IP address:local port, foreign IP address:foreign port), there will also be an associated socket at each end, corresponding to the internal representation of the connection by the protocol stack on that node, which are referred to locally by numerical socket descriptors, say 317 at one side and 922 at the other. A process on node 10.20.30.40 can request to communicate with node 50.60.70.80 on port 8888 (request that the protocol stack create a socket to communicate with that destination), and once it has created a socket and received a socket descriptor (317), it can communicate via this socket by using the descriptor (317).
 

Protocol stacks, usually provided by the operating system, is a set of programs that allow processes to communicate. The API that programs use to communicate using network sockets is called a socket API.

In TCP and UDP (standard Internet Protocols), a socket adress is the combination of an IP adress and a port number.

Ex: Sending the string "Hello, world!" via TCP to port 80.
Socket socket = getSocket(type = "TCP")
connect(socket, address = "1.2.3.4", port = "80")
send(socket, "Hello, world!")
close(socket)