Most video or audio playing software (like VLC) have a way to stream content from an HTTP server using range requests. Let's create a bridge that exposes our application as an HTTP endpoint.
Make sure the bridge supports the HTTP Range
header.
When an HTTP client wants only part of a file being served by the
server, it can set the Range
header to indicate which bytes it wants
to fetch:
Range: bytes=500-999
Use the range-parser module to make this easy.
Here's some files to get started:
client.getHandshake(callback)
- The callback will be called with
an optional error object as the first argument and an object as the
2nd: {type: 'handshake', mimeTyoe: '...', hashses: [...], chunkSize:
..., fileSize: ...}
client.getData(index, callback)
- The index
argument is the
chunk number. The callback will be called with an optional error
object as the first argument and the chunk as the 2ndCreate an HTTP server that bridges the p2p application.
Share a video file using the server and see if you can play it in VLC by connecting to the bridge.
If you get this far, here's a few ideas for how to expand your p2p program: