Created
April 24, 2011 20:07
-
-
Save moderation/939839 to your computer and use it in GitHub Desktop.
golang websockets client
This file contains hidden or 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" | |
"websocket" | |
) | |
// const message = "A message" | |
func main() { | |
ws, err := websocket.Dial("ws://localhost:8000/", "", "http://localhost:8000/") | |
ws.SetTimeout(1000000000e6) | |
ws.SetReadTimeout(1000000000e6) | |
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