Skip to content

Commit

Permalink
A client server example
Browse files Browse the repository at this point in the history
  • Loading branch information
birme committed Jun 29, 2020
1 parent 2850764 commit 19c8e8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
16 changes: 16 additions & 0 deletions examples/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fs = require('fs');
const { SRTWriteStream } = require('../index.js');

const source = fs.createReadStream(process.argv[2], { highWaterMark: 1316 });
const srt = new SRTWriteStream('127.0.0.1', 1234);
srt.connect(writeStream => {
source.pipe(writeStream);
});
srt.on('error', err => {
console.error(err.message);
})

process.on('SIGINT', () => {
console.log("Closing connection");
srt.close();
});
19 changes: 11 additions & 8 deletions examples/server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const { Server } = require('../index.js');

const srtServer = new Server();

srtServer.on("message", (msg, rinfo) => {
const fs = require('fs');
const { SRTReadStream } = require('../index.js');

const dest = fs.createWriteStream('./output');
const srt = new SRTReadStream('0.0.0.0', 1234);
srt.listen(readStream => {
console.log("Client connected");
readStream.pipe(dest);
});
srtServer.on("listening", (address, port) => {
console.log(`SRT server listening on ${address}:${port}`);
srt.on('end', () => {
console.log("Client disconnected");
});
srtServer.listen({ port: 1234 });

console.log("Waiting for client to connect");

0 comments on commit 19c8e8b

Please sign in to comment.