Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions go/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ func main() {
return
}
if *raw {
conn.Write(buf[:n])
if _, err := conn.Write(buf[:n]); err != nil {
log.Printf("write: %v", err)
return
}
} else {
log.Printf("received from %s: %s", conn.RemoteAddr(), string(buf[:n]))
conn.Write(append([]byte("echo: "), buf[:n]...))
if _, err := conn.Write(append([]byte("echo: "), buf[:n]...)); err != nil {
log.Printf("write: %v", err)
return
}
}
}
}()
Expand Down
10 changes: 7 additions & 3 deletions go/webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,24 @@ func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprintf(w, `<!DOCTYPE html>
if _, err := fmt.Fprintf(w, `<!DOCTYPE html>
<html>
<head><title>Pilot Protocol</title></head>
<body>
<h1>Hello from Pilot Protocol</h1>
<p>This page is served over the Pilot Protocol overlay network.</p>
<p>You are connected to an agent at address: %s</p>
</body>
</html>`, ln.Addr())
</html>`, ln.Addr()); err != nil {
log.Printf("write response: %v", err)
}
})

mux.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"status":"ok","protocol":"pilot","port":%d}`, *port)
if _, err := fmt.Fprintf(w, `{"status":"ok","protocol":"pilot","port":%d}`, *port); err != nil {
log.Printf("write response: %v", err)
}
})

log.Printf("webserver listening on pilot port %d", *port)
Expand Down
Loading