Week 11 - Programming TCP Sockets in Node.js
Programming TCP Sockets in Node.js Eager to know how sockets are programmed in Node? There are three variants of sockets in Node - i. TCP, ii. UDP, iii. UNIX domain. In this particular post, I will show you the basics of TCP socket programming in Node.js. There are two categories of TCP socket programs you can write - i. server, ii. client. A TCP server listens for connections to it from clients and send data to the client. A TCP client connects to a TCP server exchange data with it. The communication between client and server happens via sockets. Programming TCP sockets in Node requires the net module, which is an asynchronous wrapper for network programming. The net module is capable of many things, but for today we'll just focus on creating a TCP server and a client. Writing a TCP Server Here is an example of a very simple TCP server written in Node. Read the comments thoroughly, it explains how the code works. var net = require ( 'net' ); v...