Skip to content

Instantly share code, notes, and snippets.

@rickt
Created June 23, 2014 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickt/a797018cf97f2669110d to your computer and use it in GitHub Desktop.
Save rickt/a797018cf97f2669110d to your computer and use it in GitHub Desktop.
example CLIENT code that connects to a TCP socket & sends GOB-encoded data
package main
// use this with tcpgobserver.go
import (
"encoding/gob"
"fmt"
"log"
"net"
)
type P struct {
M, N int64
}
func main() {
fmt.Println("start client")
conn, err := net.Dial("tcp", "localhost:7743")
if err != nil {
log.Fatal("Connection error", err)
}
encoder := gob.NewEncoder(conn)
p := &P{8192, 4096}
encoder.Encode(p)
conn.Close()
fmt.Println("done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment