
In this course, files will be sent “over the wire” by turning them into raw binary data (bytes) and streaming those bytes through a persistent WebSocket connection, along with a small chunk of metadata that tells the receiver what the bytes represent (for example: file name, size, type, and which chunk this is in the sequence). WebSockets are ideal here because, once the connection is established, the client and server can keep sending both text and binary messages back and forth in real time without reopening HTTP requests, which makes it easy to interleave control messages (like JSON metadata) with binary file chunks. A typical pattern is that each message includes both metadata and binary content (or sends a metadata message followed by binary frames), so that the receiver always knows how to reassemble the chunks into the original file and what to do with it when the transfer completes.
Metadata is critically important when sending data over a network because it provides essential contextual details—like file names, sizes, types—that enable the receiver to identify, route, reconstruct, and correctly interpret raw binary payloads, which alone convey no semantic meaning. In WebSockets, when sending a string via the send() method, the API automatically encodes it to UTF-8 as required by RFC 6455 for text frames, handling the protocol's built-in text assumptions transparently. However, there is no equivalent automation for files or binary data; developers must manually craft and send metadata (often as a preceding JSON string message) alongside binary chunks via send(ArrayBuffer) or Blob, ensuring the receiver knows how to reassemble and process the file appropriately
Metadata for files over WebSockets is not as simple as sending text.
Metadata is crucial because it defines the file format, structure, and meaning of bytes, preventing confusion between media data and text. For instance:
In an image, three bytes like 0xFF 0x00 0x80 represent an RGB pixel (bright red, no green, medium blue) via metadata specifying RGB order.
The exact same bytes in UTF-8 text might decode to invalid or garbled characters, as text expects printable letters, not raw color values.
When sending files over WebSockets, the basic structure is to break the file into binary chunks (ArrayBuffer/Blob) and pair each chunk with metadata such as file name, size, type, and chunk index so the receiver can reconstruct the original file correctly. WebSockets use frames under the hood, and the protocol allows binary messages with payload lengths encoded in up to 64 bits, which means a single message can theoretically carry up to 2^63−1 bytes of data, making WebSockets suitable for very large files as long as you chunk and stream them sensibly at the application level. Because WebSockets typically run over HTTPS (wss://), they inherit TLS encryption from HTTP, so file data and metadata are protected in transit in the same way as standard secure web traffic. Modern deployments can also run WebSockets over HTTP/2 or HTTP/3 stacks, benefiting from better multiplexing and performance characteristics provided by those transports while still exposing the same WebSocket API to the application. Together, this structure—binary chunks plus metadata over a secure, persistent, full‑duplex connection—is why WebSockets fit well for the file‑transfer patterns used in this course
What we will be doing in this course.
In this lecture I'll run you through the HTML and CSS. I am assuming you know the basics about how HTML and CSS work, so i'll be brief.
Before we can spin up a http server we need a .... server. In this course we'll use a Node.js server and so in this lecture I'll show you how to use init to set up a project, and will also show you how to install express and get our project ready.
Spinning up an HTTP server in Node.js using the built-in http module is straightforward and efficient. You start by importing the http module, then create a server instance using http.createServer(), which takes a callback function that handles incoming requests and sends back responses. After setting up your request handler, you instruct the server to listen on a specified port using server.listen(). This starts the server, making it ready to receive HTTP requests on that port. The simplicity and low overhead of this approach make it ideal for lightweight web servers or APIs without needing any external libraries.
In this course I will be using the express library to handle routes, so I'll show you how we use express alongside the http module for easy HTTP setup.
In this lecture we'll mount a websocket server onto our HTTP server using the "ws" library. This "ws" library is more raw than Socket.IO so once you know how to do this, you'll tackle Socket.IO like a breeze.
Writing logic for a simple ping/pong in a WebSocket server using Node.js and the ws library is like a heartbeat check to ensure the connection stays alive— the server periodically sends a "ping" signal, and if the client replies with "pong," everything's good; otherwise, drop the dead connection to avoid wasting resources. In this lecture i'll add a keepAlive property to our ws object, and then send a ping to the client every 30 seconds. If the client does not respond with a pong, we terminate the connection. Simple right?
Initiating a WebSocket connection from the browser using the native WebSocket API takes just one simple line of code. It's like dialing a phone number to open a direct live line to your server, instantly kicking off a full-duplex channel for real-time messaging without HTTP's back-and-forth overhead. Simply write const socket = new WebSocket(url); in your JavaScript (use wss:// for secure connections over HTTPS), and the browser handles the handshake automatically: it sends an HTTP Upgrade request, the server accepts, and boom—you're connected.
Ping and pong in WebSockets act like a simple heartbeat to check if the connection is still alive—either side sends a tiny "ping" control frame (opcode 0x9), and the other must immediately reply with a "pong" frame (opcode 0xA) echoing the same data, ensuring no silent failures from network glitches or dead peers. In Wireshark, these appear as distinct non-data frames amid regular messages.
Now as I explain in the lecture, you don't have to install Wireshark in this course. This is a pseudo bonus lecture where I can show you how a packet sniffer like Wireshark can see packets sent over the wire. By the end of this lecture, you'll have enough proof to see that our WebSocket connection is working and our ping/pong frames are being sent and received correctly.
As you know, I want you to become a grandmaster coder, and its for this reason that we are going to be using modern ESModules in this course to write our project code. Let's set up this modules directory in our main project file and start coding up some modules.
You'll see how to grab the username variable value, and send this via the send() method using our client's websocket connection object.
A "click" event fires on a form's submit button when the user hits Enter/Return inside an input field because browsers treat pressing Enter in a form input as an implicit submission action. This implicitly activates the form’s first submit button, causing its click handler to run.
Essentially, pressing Enter triggers the form submission process, which includes firing the submit event on the form and also invoking any click handlers attached to the submit button, simulating a user click without requiring actual mouse interaction. This built-in behavior improves usability by letting users submit forms quickly from the keyboard.
By default, whenever a form "submit" event is fired in the browser, the browser will automatically refresh the page. I don't want this to happen, as it will destroy all state as we are not saving any user data in a database.
Have you ever wondered why the web browser does an auto refresh when a submit event is fired on a <form> element?
In our Node.js app.js file using the ws library, we set up a WebSocket server that listens for incoming client connections.
Now for each connection, we will attach event handlers that listen for "message" events, and within those handlers, we use switch statements to determine the type of message received and direct the flow of code execution accordingly. This design allows us to efficiently handle different message types or commands received over the WebSocket connection in a structured and maintainable way.
In this course, we use a Map instead of traditional arrays to store WebSocket connections because Map provides efficient key-value storage and quick lookup capabilities. Its also modern JavaScript as I keep saying, I want you to become a grandmaster. Maps allow us to associate each WebSocket connection with a unique username, making it easy to manage and access individual client connections. Unlike arrays, which require linear searches to find specific connections, Maps enable constant-time lookups and cleaner code when handling large numbers of connections. This approach improves performance and organization when managing multiple WebSocket clients on the server side.
Just to clarify, i want to explain how I view Map and why i'm using it.
When a user types in a username, our server needs to check whether the Map of connected users "has" that username as a key. if so, we will send back a failure response back to the client because in our application every username should be unique.
If the username does not exist, then we can send back a success response over the ws connection using the ws.send() method.
At this point in the course, the client has sent a message over the ws connection to the server, with their username. The server then listend for incoming events, parsed the message back into a JS object, and then updated the Map object with this username and asscociated ws connection. The server then sent back a response to the client right, indicating that the username is okay, or worst case, if its taken and thus failed. In this lecture, you will learn how to set up a "message" event handler on a client WebSocket connection using the browser's native WebSocket API to listen for incoming message events from the server. We will implement a simple JavaScript "Switch" statement to test for different message types. If the username is successful, we will also dynamically show other UI elements on the page so the user can select which user they want to send a file to, and upload their file and hit send.
In this lecture we will use JavaScript's Array.from() method to create an array from the Map of all connected clients. We are doing this so that we can grab only all usernames and send that back to each browser. Why? Simple. Each client's browser needs to loop through all currently connected users and then update the <select> element accordingly.
In the next lecture we will use JavaScript to dynamically update the HTML <select> element by inserting <option> elements inside of which, where each <option> has a "value" attribute. Before I code this with you, I wanted to explain in my own words how this works. Once you master this, then the next lecture will be a breeze.
Its finally time to show you the power of WebSockets - how it can "push" users to each connected client and the browser can dynamically add a new user to the dropdown.
As we've seen in the previous lecture, when a user closes a WebSocket connection (for example by closing their browser) then nothing happens. So in this lecture we need to listen for the WebSocket "close" event which will be fired natively by the browser API. We then, on our server, need to remove that user from our Map object and then broadcast an updated list of all users to all connected clients.
Well done for completing this section. In this lecture we will do final testing and update our UI.
Well done for completing this section.
A brief description of next steps we'll take.
Welcome to this section. Super excited to get into it.
Right now, when a user selects a receiver, nothing happens. This is because by default all my form related controls are disabled. I did this so that we can enable some checks and logic before we allow the user to select a file. That's why we need to now enable the <input type="file"> element once a user selects a valid user/receiver.
When you select a file on a website, your operating system opens a secure file picker that lets you choose exactly which file to share, preventing access to anything else on your computer. The browser reads the file data into memory or processes it in chunks without retaining or exposing the file’s actual disk path to websites or scripts. This path is only briefly handled internally by the browser’s native code during the initial file read and is never stored or shared, protecting your privacy. Although a malicious browser could theoretically try to keep the real file path, major browsers like Chrome, Firefox, and Safari have strict security measures to prevent this, ensuring only the chosen file’s content is accessible while keeping your file locations private and safe.
A brief explanation about what we discussed in the previous lecture.
Every input element in HTML that has its type attribute set to "file" allows us to extract the file the user has selected, via the files property. The object returned to us is in the form of a FileList, which is not a pure Array. But its similar to an array in that we can iterate through it and extract its items.
As you'll see in this lecture, the FileList gives us the users selected file, but only metadata. We can see file size, type and name, but we still at this point are not allowed to view the actual file contents itself.
In this lecture when the user clicks "Send" after selecting their file, I want to register a "click" event handler so we can now start the process of reading the selected file into memory and sending the file over our WebSocket connection to the receiver.
When a user selects a file in our WebSocket-based file transfer app, the client first extracts key metadata, such as the file's name, size, MIME type from the File API object before sending it to the server as a JSON-formatted text message over the WebSocket connection. This initial message allows the server to notify the receiver without yet receiving the binary data. The server parses this JSON upon receipt in its ws.on('message') handler, and broadcasts the details.
Our server now gets a websocket message containing the file metadata. Inside the metadata object, we also included the receiver's username so that the server can find this receiver's websocket connection inside of the users Map and relay that message to the correct user.
The browser's WebSocket API infers message type from the ws.send() argument: strings like JSON.stringify(obj) trigger opcode 1 (text frame) per RFC 6455, while ArrayBuffer/Blob use opcode 2 (binary); no special JSON flag is set. On the Node.js ws server, the message event's isBinary property is false for text frames (opcode 1), detected via the library's frame header parsing and unmasking process
We need to listen for incoming "message" events fired on the receiver's websocket connection, in the browser. Remember this is client-side. We will then extract the file metadata and view it in the console.
The FileReader API enables web applications to asynchronously read file contents or Blob data client-side without server involvement. The line let reader = new FileReader() creates a new FileReader instance, which provides methods like readAsText(), readAsArrayBuffer(), or readAsDataURL() to process the file data into formats such as strings, binary buffers, or base64 URLs. After instantiation, attach event handlers like onload to access the result via reader.result once reading completes
The FileReader API operates asynchronously under the hood by initiating a non-blocking read operation from the browser's file system when methods like readAsArrayBuffer() are called on a File or Blob object, allowing the main thread to continue executing without freezing the UI. Once the data is fully loaded into memory (as an ArrayBuffer, text, or data URL), the browser dispatches a load event on the FileReader instance, which developers must listen for via reader.onload or addEventListener('load', handler) to access the processed content through reader.result—attempting to use the result prematurely yields empty or undefined data. The readAsArrayBuffer method is the most common for binary file handling, especially in WebRTC/WebSocket transfers, but for large files exceeding browser memory limits (like your 3 GB case), implement chunking by slicing the File into smaller Blobs (e.g., 64-256 MB each) and reading them sequentially in a loop, awaiting each load event before proceeding to avoid heap exhaustion
It's always nice to add visual feedback to the user, right? So in this lecture let's initialize our HTML <progress> element. The HTML <progress> element requires setting the max attribute upfront to define the total work required for a task, such as the full file size in bytes (e.g., progress.max = file.size), establishing the scale from 0 to that maximum for accurate percentage visualization—defaults to 1 if omitted. The value attribute starts at 0 and updates dynamically during operations like chunked FileReader processing. In this lecture we will set its value static at 0 but later you'll see how we will dynamically change this value.
I want to show you in this lecture what happens if you pass in the entire file into the reader.readAsArrayBuffer(file) method. If the file is small, not much will happen. But the problems occurs for larger files.
I want to prove to you that we are not able to pass in large files into the FileReader API if they exceed what a browser allows. By default any failure will occur "silently". This just means that we will not automatically get told what went wrong. That's why we have to set up an onerror event listener on our reader to catch these sort of errors.
Creating on-demand dummy files via command prompt is invaluable for testing file transfer apps over WebSockets, like simulating your 3 GB scenarios without real data. On Windows, run fsutil file createnew testfile.bin 3221225472 in an admin Command Prompt to instantly generate a sparse 3 GB file (using binary GiB sizing)—it's allocated but doesn't consume full disk space until written, enabling rapid tests of chunking, progress bars, and memory limits in FileReader/WebSocket pipelines.
FileReader.readAsArrayBuffer() attempts to load entire files into memory, triggering browser-specific pre-read checks that cause inconsistent failures: a 2GB file often skips loadstart due to early memory rejection (e.g., heap limits, disk block misalignment, or Chrome heuristics), firing only loadend + error, while a 5GB file passes initial checks, starts reading (loadstart fires), then crashes mid-process
We are coding up and developing an application that transfers files using WebSockets. To test our application we need ... you guessed it, FILES. You can of course use any file on your system, but if you want a quick and dirty way to generate a file of any size for testing, here are some methods you can type into your terminal to get the job done.
Computers are built on binary, so memory sizes are naturally powers of 2, and 2^10=1024 is the first “nice” size near 1000. Historically, engineers started calling 1024 bytes a “kilobyte” because it’s convenient in hardware and close to “about a thousand,” even though in strict SI terms kilo means 1000.
The slice(start, end) method on a Blob or File object creates a new Blob containing only a specified byte range from the source. We will also use the concept of offsets to keep track of which part of a file we want the reader to read into memory next.
Remember, one of the downsides with the FileReader API is that we have the burden of writing all logic to read the file. This includes telling the parser how much of the file we want it to read into memory at a time. In fact, its worse than this because we have to tell the parser exactly which portion of the file (start and end) we want it to read. Now, how large should each chunk be? This is the million dollar question, right. In this lecture I'll show you different ways of defining a chunk size. We could set the size as being fixed, or we can set it dynamically using the navigator object on the browser.
Before you can run, you need to learn how to walk. So before we finish writing all of our code, lets test to see if we can successfully read one chunk of file data, and then send that chunk to our ws server using the ws.send() method.
Proof is in the pudding. In this lecture lets implement a simple IF statement in JavaScript to check whether our offset value (effectively this is the amount of bytes we've read into memory) is equal to the file.size property. If it is equal to this value, then we know the file reading process is complete. If its not equal to that value, for instance its less than that value, then we know we need to read yet another slice via the readSlice() function.
Your ws library WebSocket server has a default maxPayload limit of 100MB (104857600 bytes) per message—this is what trips the "chunks exceeding maximum size limit" error when clients try sending bigger payloads (like large file chunks over WS). Every WS library enforces some max payload check for security (to avoid memory bombs from malicious giant messages), so you always need to verify and tweak it explicitly if handling big data; ws lets you set it higher via new WebSocket.Server({ maxPayload: 50 * 1024 * 1024 }) (e.g., 50MB), but watch your server's RAM.
Socket.io does have max payload limits too—defaults to 1MB for incoming messages (way tighter than ws!), configurable via maxHttpBufferSize and pingTimeout options on the server. It fragments big messages automatically, but if a single chunk/frame blasts past the limit, you'll get errors. For file transfers, chunk your data client-side to stay under (e.g., 512KB chunks), bump the limit server-side, and maybe add flow control—beats DoS headaches every time!
The ws WebSocket server has a default maxPayload limit (which is what triggers the “chunks exceeding maximum size limit” error when clients send messages that are too large), and every WebSocket library you use will enforce some kind of maximum payload size for security, so it’s important to know and adjust that if you’re dealing with big data. In this course, the chunk sizes are kept small so you never hit that limit, but if you wanted to, you could raise it in ws when creating the server (for example, setting maxPayload to a higher value) while keeping an eye on your server’s memory usage. Socket.io also has a maximum message size (commonly much smaller by default), which you can increase with its configuration options, but if a single chunk goes over that, you’ll still see errors. The main takeaway is: for file transfers, chunk data on the client, optionally raise the server limits, and add flow control (for example, by watching bufferedAmount) so everything stays fast and stable.
There is no point in continuing the read the file, if the underlying websocket connection between the sender (client) and the server has been closed. So if the readyState property is not in the OPEN state, why don't we return out of the entire function and stop the reader. Perhaps a better way to manage this is to call reader.abort(), but either approach will work.
The WebSocket API's bufferedAmount read-only property provides developers with insight into flow control by reporting the number of bytes queued via send() calls that are awaiting transmission over the network, enabling monitoring of the send queue to prevent overload. This value, an unsigned long, resets to zero only after all buffered data transmits successfully but persists and accumulates even if the connection closes, allowing continued queuing without reset. In upcoming lectures, this property will be leveraged to implement safeguards, ensuring the queue stays below safe thresholds for optimal performance and avoiding issues like head-of-line blocking in real-time applications
Because my network speed is fast, we are not really having any issued with the bufferedAmount property. Remember this represents the amount of data queued to be sent over the websocket network, but that is currently pending. In this lecture I'll show you why its important for our code to handle flow control. Spoiler alert: the specification for websockets explicitly states that if the buffered amount gets too big, then the underlying ws connection needs to be closed. we of course don't ever want this to happen.
Before we send our data via the ws.send() method, I want to implement flow control. Specifically, I want to use a while() loop, which is a function given to us by JavaScript, to check the bufferedAmount property.
The code i'll write with you in this lecture prevents overwhelming a WebSocket connection by checking if the amount of unsent data (bufferedAmount) exceeds a defined limit (MAX_BUFFERED_AMOUNT). While the buffer is too full and the connection is still open, it pauses execution in short 10‑millisecond intervals, printing a warning message each time. This allows time for the data in the buffer to be sent before continuing, keeping the connection stable and preventing message loss or congestion.
These concepts you are learning are advanced, so let me explain what we've just done.
let's test our flow control logic to make sure everything is working. I can't wait.
At this point in time, our WS server has received its first chunk of file binary data. It captures this event in the "message" event handler function, and we know it is of type binary. We already have a property on the senders websocket object that contains the receivers username, so we can simply access this value, and then utilize our Users object (which if you will remember is of type Map), to then access the receivers WS connection object so that our server can send this user the file chunk.
In this lecture we will set up our base receiver function to handle binary data received. I'll also show you that by default, the browser's WebSocket object will decode all incoming data into a Blob object. However, a Blob object is limiting for developers as it merely gives us raw bytes that we can't view or manipulate. So that's why its often more convenient to tell the WebSocket API to convert all data into an ArrayBuffer instead. The good news is that this is super easy to do, as there is a binaryType property given to us automatically.
Let's access the HTML <progress> element for the receiver, and update their progress bar "value" property dynamically. Remember we are also receiving file chunks from the server, so we need to store these chunks somewhere until the download is complete, don't we? Yes, absolutely. So why don't we create an array, and push all chunks received into that array.
URL.createObjectURL() converts a Blob (or File) into a temporary blob: URL that browsers can use like any other link. To create a download link, you pass your Blob to this method to get a URL (e.g., blob:http://...), then set that as the href on a dynamically created <a> element along with a download attribute specifying the filename. Programmatically clicking the anchor triggers the browser's native download dialog, saving the Blob's data as a file—perfect for in-memory data like received WebSocket binaries, without needing a server.
Proof is in the pudding, and in this lecture i want us to test our code thus far, and also get you to think about memory allocation in the browser from both the senders and receivers perspective.
From the senders side, the browser's file reader has to read the file data into its own memory. Although we implement chunking, it makes sense that the browser still needs to keep some of these chunks in memory because some chunks persist in a buffer while the network is sending data. Only once garbage collection kicks in, does the browser automatically delete the array buffers by default. I will show you how to view this memory heap in the browser and how to manually force the browser to implement garbage collection.
From the receivers perspective, we have stored every chunk received in an array. I want to prove to you that you can view the memory heap in real time to see what happens if we don't empty this array after the user has consumed all the array buffers to create a blob.
We are digging into some advanced concepts, but hey, I want you to become a grandmaster. In this lecture I'll try explain in my own simple way how you should view memory allocation when a user sends a file using websockets. I also want to show you that browsers have internal pages that allow you to view the Blob data associated with a session. pretty cool,, huh?
The 2× JS heap spike occurs when new Blob(receivedFileBuffer) executes because your ~25 MB of ArrayBuffers in the array remain live alongside the Blob's new backing store allocation (often a full contiguous copy), both visible in DevTools' JS heap view during construction. The heap then drops seconds later after receivedFileBuffer = [] makes the old buffers GC-eligible and the local blob variable goes out of scope, with GC reclaiming that memory—while the Blob's underlying bytes survive in the browser's separate Blob storage system (RAM, shared memory, or disk via IPC), invisible to the JS heap graph and kept alive by the blob: URL until revokeObjectURL()
So we've seen in the previous few lectures how the browser manages internal memory consumption when a sender sends a file, and a receiver starts processing those chunks and ultimately creates a Blob URL for download. In this lecture we will use the URL.revokeObjectURL() method to tell the browser to clear its Blob memory after the user has download the file.
What if the sender of the file has blundered, and does not want to send the file? Well, we have a Stop button for this very reason. In this lecture let's implement a flag when the user clicks on the abort button to indicate that they no longer wish to send the file. We will then check this flag value every time we read a chunk of a file and if the flag is set to true, we will stop the reading operations immediately.
Well done for sticking with me this far. Seriously, we've come a far way. We've written modern JavaScript to implement a fully functional WebSocket file transfer application. You're a true champion.
Attached are the final code files for this section.
The Streams API is a web platform standard that enables JavaScript to handle streaming data efficiently by processing it in small chunks rather than loading entire resources into memory at once. It provides three core interfaces: ReadableStream for sources of data, WritableStream for sinks, and TransformStream for data transformation. This allows developers to pipe streams together, apply backpressure to control flow, and manage continuous or large datasets like network fetches, file reads, or media processing.
Of course, in this course (haha ... double use of the word "course"), we will be using the ReadableStream interface to read chunks of our file asynchronously.
A summary of the theory when it comes to the Streams API
To read a file using the Streams API, follow a deliberate three-step process: First, call file.stream() on a File object (e.g., from <input type="file">) to obtain a ReadableStream<Uint8Array> that exposes the file's bytes as a controllable pipe for chunked access. Second, invoke stream.getReader() to create a ReadableStreamDefaultReader, which locks the stream exclusively to that reader, preventing concurrent consumption and ensuring consistent data flow. Finally, repeatedly call reader.read() in a loop (e.g., while(true) { const {value, done} = await reader.read(); if(done) break; /* process value as Uint8Array */ }), yielding promises that resolve to {value: Uint8Array, done: boolean} chunks for incremental processing without loading the entire file into memory.
lets continue to code up our application in this lecture.
In oursendFile function's while(true) loop, we are using break (e.g., on done and abortSend) to exit only the reading loop, ensuring execution reaches the finally block where reader.releaseLock() runs to unlock the stream—critical for resource cleanup and allowing the stream to be garbage collected. Using return instead would immediately exit the entire sendFile function, bypassing the finally block entirely (since return terminates before cleanup), leaving the stream permanently locked and potentially causing memory leaks or preventing other code from reusing the stream, while also skipping any post-loop UI updates or WebSocket state handling
When using the Streams API to read file chunks via ReadableStreamDefaultReader.read(), each call yields a {value, done} result where value is a Uint8Array containing a chunk of binary data from your file. Directly pass this value buffer to ws.send(value) to transmit the raw chunk over WebSocket to your server, avoiding unnecessary copies or base64 encoding that bloats bandwidth. This streams the file progressively without loading it fully into memory, with backpressure handled automatically.
its time to put our money where our mouth is - does our code work?
When the done boolean is set to true on the object returned to us by the Streams API, we are currently only breaking out of the while loop. However, why don't we just add some minor UI logic to improve the visual feedback to the sender that their file send operation has been completed.
Final project files attached.
A big thank you for your amazing support and well done for completing the course. I hope, my dear student, to see you in a future course.
*** BEST WEBSOCKET FILE TRANSFER COURSE IN 2026 ***
Code a file transfer app using a WebSocket server
Understand how WebSockets can relay files between clients via a central server
Master the FileReader API, Streams API and Blobs
Work with Blobs to assemble received file chunks into a downloadable link
Learn the importance of sending file metadata (filename, size, type)
Explore chunking strategies to split files into manageable pieces
Gain insight into browser memory handling, JavaScript heap memory and browser Blob internal storage
Understand how to avoid memory bloat by cleaning up memory after code completion
Equip yourself with best practices for WebSocket server setup and connection management to build robust and scalable file sharing apps.
And more!!!
Feel like diving in and touching the bottom? Now’s your chance. Code an app that sends large files to another device. Use a lightweight WebSocket server to relay data reliably between clients.
TWO (OF MANY) REASONS WHY THIS COURSE IS A GAME CHANGER:
Together we build a complete file-sharing project from scratch using a simple WebSocket server. No complex P2P setup required. This course provides practical skills like no other.
You will use WebSockets for this, which is a modern, reliable and secure technology for real-time messaging. This course covers WebSockets sufficiently for its purposes, but those wanting a more comprehensive overview may consider specialized WebSocket courses, like my WebSockets course.
Other mainstream sites (like SendBig, TransferNow, WeTransfer, etc) use servers and traditional methods to send files. This course teaches you how to build efficient file transfers using a WebSocket relay server, making your file sharing fast, secure, and scalable. Server-relayed, real-time transfer between any devices. How amazing is that?
Sending files via a WebSocket server is a critical, high-demand skill in modern web applications, and this course teaches you how to do it using battle-tested WebSocket technology. You will master building server-relayed file transfers that handle real-world scale, ensuring file sharing is fast, secure, and efficient.
Why sending files is complicated?
The journey of transferring a file over WebSockets follows this path:
"file on sender's hard drive → browser memory → WebSocket message → relay WebSocket server → receiver’s WebSocket → receiver’s browser memory → receiver’s disk"
Sounds simple, right?
But here’s the catch: if we try to load the whole file into browser memory at once, we hit RAM limits imposed by browsers. To overcome this, we use chunking, breaking the file into manageable pieces.
But wait, chunking alone isn’t the end of the story. Chrome and others fragment larger payloads, but we must chunk file data to fit these limits reliably. So not only do we chunk the file for reading, but we also send those chunks as small WebSocket messages to avoid fragmentation issues.
But wait, we're not done. Here’s where it gets tricky: your browser often reads chunks and calls the send() method faster than the WebSocket network can transmit them to the server. This creates a send buffer, a backlog that, if ignored, can crash your connection with errors. That’s why you’ll master how to monitor the bufferedAmount, ensuring smooth data flow and keeping connections stable.
This course makes these complex challenges simple and practical, turning you into a savvy WebSocket file transfer expert!
Why this Course Matters
Reliable Server-Relayed File Transfer: Learn how WebSockets enable efficient client-to-server-to-client communication for files, with a simple relay server handling the routing.
Real Project Setup: Build a native HTTP server with Node.js and a WebSocket server (using ws library), then connect clients for seamless file relaying.
Deep Dive into Files: Understand what files really are at the binary level, and why browsers require files to be read into memory before sending.
Practical Use of the FileReader API: Master the most popular API for reading files into browser memory and the necessity of chunking files to avoid RAM limits.
Modern Streams API: Utilize the more modern Streams API for file transfer.
Metadata and File Reconstruction: Implement logic to send metadata and reassemble chunks on the receiver side, creating downloadable URLs from blobs with the URL.createObjectURL() method.
Interactive Learning: Benefit from quizzes, write-ups, and thorough explanations designed to make you a WebSocket file transfer grandmaster.
What You Will Build
In this course you'll build a fully functional file transfer application that allows a sender to select a file, send it chunk-by-chunk over a WebSocket connection to a relay server, and create a download link on the receiver’s end, ready for users to save their files locally.
Course Highlights
Understanding files as computer and browser objects.
Setting up essential WebSocket signaling with Node.js HTTP and ws servers (we will use Node.js)
Overcoming browser memory limits with chunked reading and sending.
Handling WebSocket message constraints and send buffer management.
Exploring multiple APIs including FileReader, Blob transmission, and Streams API.
Creating reliable file reconstruction and user-friendly download links.
Experiential learning through real project code, quizzes, and explanations.
But wait, there's more!
This course also discusses memory implications for sending files directly via a WebSocket server as binary data. Specifically, you'll see how the browser keeps a snapshot of all JavaScript objects and data in a "heap". You'll also learn that once the browser creates a Blob url from the file data, it needs to also store that data somewhere, usually on the users local machine in a special folder. At some point, you'll want to ensure that memory does not bloat, so you will learn how to allow JavaScript's garbage collector to kick in. Sounds crazy, right? Don’t sweat it though, I’ve got your back, and together we’ll crack these puzzles.
Meet Your Instructor: Clyde
Clyde is a lifelong coding enthusiast who has been hooked on computers since he was 7 years old. With years of hands-on experience in web development and a passion for teaching, he brings a treasure trove of practical knowledge and real-world insights to this course. Known for his engaging and approachable style, Clyde breaks down complex concepts into clear, enjoyable lessons that anyone can follow.
You might be wondering, is he an AI? Nope, Clyde is 100% human (or is this something a robot would say ?!), and he’ll be right there with you throughout every lecture, your dedicated wingman as you tackle challenges, celebrate breakthroughs, and master the skills step by step.
This course is far from a solo adventure. With Clyde as your companion, you’ll feel supported and inspired as you journey from beginner to WebSocket file transfer pro. Let’s get crackin’
Why This Course Is Different
It’s comprehensive, hands-on, and rooted in real-world challenges like chunking, buffer management, compression issues, and server relaying. Unlike generic tutorials, you get deep understanding and practical skills that today’s employers and projects demand.
Enroll now to become an expert in server-relayed file transfer with WebSockets. Advance your development skills, build secure, efficient apps, and join a thriving community of forward-thinking web developers.
Let’s get crackin’