Simulate streaming data

I am trying to write a program that will read from a flat data file and simulate streaming, so that I can test a program that reads streaming data without the need to connect and start streaming equipment.

What are the most realistic ways to achieve this? I need it to be broadcast at a variable speed depending on the simulation equipment.

So far, my two ideas are a program that writes to a named pipe or a program that writes to a virtual serial port at the rates that I need.

Is there a better (more realistic) way to simulate streaming data?

+3
source share
3 answers

, . Perl

use Socket;
socketpair my $A, my $B, AF_UNIX, SOCK_STREAM, PF_UNSPEC;

if (fork() == 0) {
    stream();
    exit;
}

while (<$A>) {
    print;
}

sub stream {
    # output 1024 bytes/sec
    select $B; $| = 1;          # disable output buffering
    open my $fh, '<', '/file/to/stream';
    my $buffer;
    while (my $n = read $fh, $buffer, 1024) {
        sleep 1;
        print $B $buffer;
    }
    close $fh;
}
+3

, . . , ; , .. ( , ).

, , , . , , , . YMMV.

, , / .

+1

You can try to save some coding time by looking at the trickle (user space bandwidth shaper).

0
source

All Articles