O'Reilly logo

Node.js, MongoDB, and AngularJS Web Development by Brad Dayley

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

Implementing a TCP Socket Server

At the most basic level, implementing a TCP server client involves creating a Server object, listening on a port, and handling incoming connections, including reading and writing data to and from the connections. In addition, the socket server should handle the close and error events on the Server object, as well as the events that occur in the incoming client connection Socket object. This section discusses the steps involved in implementing a socket server using the Server object. Listing 8.2 provides the full code for the following discussion.

The first step is to create the socket server by calling net.createServer(), as shown below. You also need to provide a connection callback handler and then call listen() ...

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