O'Reilly logo

Learning Node, 2nd Edition by Shelley Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Networking, Sockets, and Security

The core of a Node application invariably relies on two primary infrastructure components: networks and security. And you can’t talk about networks without also discussing sockets.

I group networks and security because once you start moving beyond a single, isolated machine, security should be paramount in your mind at all times. Every time you finish a new piece of the application, the first question you should ask yourself is: is this secure? No amount of graceful coding can compensate for letting crap in.

Servers, Streams, and Sockets

Much of the Node core API is related to creating services that listen to specific types of communications. In Chapters 1 and 5 we used the HTTP module to create web servers listening for HTTP requests. Other modules can create a Transmission Control Protocol (TCP) server, a Transport Layer Security (TLS) server, and a User Datagram Protocol (UDP) socket. I’ll cover TLS later in the chapter, but in this section I want to introduce the TCP and UDP Node core functionality. First, though, a quick look at sockets.

Sockets and Streams

socket is an endpoint in a communication, and a network socket is an endpoint in a communication between applications running on two different computers on the network. The data flows between the sockets in what’s known as a stream. The data in the stream can be transmitted as binary data in a buffer, or in Unicode as a string. Both types of data are transmitted as packets ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required