Skip to content

Instantly share code, notes, and snippets.

@joshlf
Created August 28, 2014 00:48
Show Gist options
  • Save joshlf/62a64b37670df1ca551c to your computer and use it in GitHub Desktop.
Save joshlf/62a64b37670df1ca551c to your computer and use it in GitHub Desktop.
UDP Streaming at 16 kbps
package main
import (
"fmt"
"io"
"net"
"os"
"github.com/synful/rate"
)
func main() {
fmt.Println(handle("/dev/urandom", "localhost:8080"))
}
func handle(fname, addr string) error {
f, err := os.Open(fname)
if err != nil {
return err
}
c, err := net.Dial("udp", addr)
if err != nil {
return err
}
_, err = io.Copy(rate.NewLimitWriter(c, 16*1024/8), f)
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment