Created
August 28, 2014 00:48
-
-
Save joshlf/62a64b37670df1ca551c to your computer and use it in GitHub Desktop.
UDP Streaming at 16 kbps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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