Created
January 9, 2016 17:24
-
-
Save ivan3bx/ca3ebadcb0a9d6fc7de8 to your computer and use it in GitHub Desktop.
Simple 'echo' server with golang.org/x/net/websocket
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/http" | |
"reflect" | |
"golang.org/x/net/websocket" | |
) | |
// Echo the data received on the WebSocket. | |
func EchoServer(ws *websocket.Conn) { | |
fmt.Println(reflect.TypeOf(ws)) | |
io.Copy(ws, ws) | |
} | |
// This example demonstrates a trivial echo server. | |
func main() { | |
http.Handle("/", websocket.Handler(EchoServer)) | |
err := http.ListenAndServe(":7474", nil) | |
if err != nil { | |
panic("ListenAndServe: " + err.Error()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment