Understanding Network Sockets

Network sockets are endpoints of communications that flow across a computer network. Sockets live below the HTTP layer and provide the point-to-point communication between servers. Virtually all Internet communication is based on Internet sockets that flow data between two points on the Internet.

A socket works using a socket address, which is a combination of IP address and port. There are two types of points in a socket connection: a server, which listens for connections, and a client, which opens a connection to the server. Both the server and the client require a unique IP address-and-port combination.

The Node.js net module sockets communicate by sending raw data using Transmission Control Protocol (TCP). This protocol is responsible for packaging data and guaranteeing that it is sent from point to point successfully. Node.js sockets implement the Duplex stream, which allows you to read and write streamed data between the server and client.

Sockets are the underlying structure for the http module. If you do not need the functionality for handling web requests like GET and POST and you just need to stream data from point to point, then using sockets gives you a lighter-weight solution and a bit more control.

Sockets are also extremely handy when communicating with other processes running on the same computer. Processes cannot share memory directly, so if you want to access data in one process from another process, you can open up the same socket in each process and read and write data between the two processes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset