Frederic G. MARAND 4 years ago
parent
commit
30e6db1a44
4 changed files with 13 additions and 4 deletions
  1. 4 0
      Makefile
  2. 3 0
      part2/go.mod
  3. 0 0
      part2/go.sum
  4. 6 4
      part2/main.go

+ 4 - 0
Makefile

@@ -0,0 +1,4 @@
+all: clean
+
+clean:
+	rm -f */wg

+ 3 - 0
part2/go.mod

@@ -0,0 +1,3 @@
+module code.osinet.fr/fgm/whispering_gophers
+
+go 1.12

+ 0 - 0
part2/go.sum


+ 6 - 4
part2/main.go

@@ -32,13 +32,15 @@ type Message struct {
 }
 
 func main() {
-	// TODO: Parse the flags.
+	flag.Parse()
 
-	// TODO: Open a new connection using the value of the "dial" flag.
-	// TODO: Don't forget to check the error.
+	c, err := net.Dial("tcp4", *dialAddr)
+	if err != nil {
+		log.Fatal(err)
+	}
 
 	s := bufio.NewScanner(os.Stdin)
-	// TODO: Create a json.Encoder writing into the connection you created before.
+	e := json.NewEncoder(c)
 	for s.Scan() {
 		m := Message{Body: s.Text()}
 		err := e.Encode(m)