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() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access