Skip to content
Snippets Groups Projects
Commit b6d69e58 authored by Thomas Schneider's avatar Thomas Schneider
Browse files

Initial import

parents
No related branches found
No related tags found
No related merge requests found
/wsshit
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
LICENCE 0 → 100644
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
go.mod 0 → 100644
package main
import (
"flag"
"io"
"log"
"net/http"
"os"
"time"
"github.com/gorilla/websocket"
)
var (
listen = flag.String("listen", ":10042", "address to listen on")
file = flag.String("file", "", "file to serve")
upgrader = websocket.Upgrader{}
data []byte
)
func jpeg(w http.ResponseWriter, r *http.Request) {
c, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Print("upgrade: ", err)
return
}
defer c.Close()
log.Printf("initialised websocket with %v", c.RemoteAddr())
// 114ms ~ 8.7Hz
tick := time.NewTicker(114 * time.Millisecond)
defer tick.Stop()
for range tick.C {
c.WriteMessage(websocket.BinaryMessage, data)
}
}
func main() {
flag.Parse()
f, err := os.Open(*file)
if err != nil {
log.Fatal(err)
}
data, err = io.ReadAll(f)
if err != nil {
log.Fatal(err)
}
f.Close()
http.HandleFunc("/jpeg", jpeg)
log.Printf("listening on %s", *listen)
log.Fatal(http.ListenAndServe(*listen, nil))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment