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() ...
Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.