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
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