Free course

Socket Programming with Node.js

Build TCP and UDP programs with Node.js, frame messages, handle unreliable connections, and design a small protocol you can inspect on the wire.

5 modules · 25 lessons · No signup

Prerequisites: JavaScript, Node.js and Networking Foundations

~~~

Your progress

of lessons completed.

Course completed.

What you'll learn

Build and test TCP and UDP clients and servers that frame input, apply limits, handle failures, and support multiple clients safely.

Take this course offline

Subscribe to my newsletter to get every free book and course in PDF and EPUB format.

Get the downloads

Course contents

  1. TCP foundations

    Build a TCP server and client, exchange bytes, and control the listening address.

    1. Build a TCP server
    2. Build a TCP client
    3. Treat TCP as a byte stream
    4. Choose a listening address
    5. Check your understanding: tcp foundations
  2. Message framing

    Build a newline protocol, buffer partial input, parse JSON messages, and enforce size limits.

    1. Design a newline protocol
    2. Buffer partial lines
    3. Send length-prefixed messages
    4. Frame JSON messages
    5. Check your understanding: message framing
  3. Connection reliability

    Handle timeouts, half-closes, resets, backpressure, and cleanup without leaking resources.

    1. Add an idle timeout
    2. Handle end, close, and errors
    3. Respect backpressure
    4. Limit connections and work
    5. Check your understanding: connection reliability
  4. UDP datagrams

    Build UDP endpoints, preserve message boundaries, and add retries, identifiers, and duplicate handling.

    1. Build a UDP server
    2. Send a UDP datagram
    3. Add request identifiers
    4. Design for loss and reordering
    5. Check your understanding: udp datagrams
  5. Build and test a protocol

    Specify commands, validate limits, support concurrent clients, inspect packets, and finish a small service.

    1. Write the protocol contract
    2. Validate before changing state
    3. Support concurrent clients
    4. Capture and finish the service
    5. Check your understanding: build and test a protocol