Created
October 30, 2016 10:05
-
-
Save Gitart/d83fdbe02c772aeff2a1f17226c5be31 to your computer and use it in GitHub Desktop.
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" | |
"code.google.com/p/go.net/websocket" | |
) | |
const message = "Hello world" | |
func main() { | |
ws, err := websocket.Dial("ws://localhost:8082/echo", "", "http://localhost:8082") | |
if err != nil { | |
panic(err) | |
} | |
if _, err := ws.Write([]byte(message)); err != nil { | |
panic(err) | |
} | |
var resp = make([]byte, 4096) | |
n, err := ws.Read(resp) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("Received:", string(resp[0:n])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment