Skip to content

Instantly share code, notes, and snippets.

@AlphaWong
Forked from jeremywho/server.go
Created January 3, 2018 15:46
Show Gist options
  • Save AlphaWong/0765513eca7215b73dd871178caa4da2 to your computer and use it in GitHub Desktop.
Save AlphaWong/0765513eca7215b73dd871178caa4da2 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
"github.com/gorilla/websocket"
)
func echo(w http.ResponseWriter, r *http.Request) {
upgrader := websocket.Upgrader{}
conn, _ := upgrader.Upgrade(w, r, nil)
defer conn.Close()
for {
mt, message, _ := conn.ReadMessage()
fmt.Printf("recv: %s\n", message)
_ = conn.WriteMessage(mt, message)
}
}
func main() {
http.HandleFunc("/", echo)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment