title: UDP server / client in Go not reading data
body: <p>I have written a UDP server and client in Go.  I am not seeing any error messages when the server is running on <code>port 1200</code>, I also do  not see any errors when client is trying to connect to port 1200 on the same machine (OS X 10.9.1)</p>
  
  <p>The server is not printing "SOS...", that is the message the client is writing, in a infinite loop.</p>
  
  <p>The client is able to send a message to the server though, however what the server is reading is 0 bytes.</p>
  
  <p>Server Code</p>
  
  <pre><code>package main
  
  import ( "net" "fmt" "time" )
  
  func main() {
  
          port := "127.0.0.1:1200"
  
          udpAddress, err := net.ResolveUDPAddr("udp4",port)
  
          if err != nil {
                  fmt.Println("error resolving UDP address on ", port)
                  fmt.Println(err)
                  return
          }
  
          conn ,err := net.ListenUDP("udp",udpAddress)
  
          if err != nil {
                  fmt.Println("error listening on UDP port ", port)
                  fmt.Println(err)
                  return
          }
  
          defer conn.Close()
  
          var buf []byte
  
          for {
  
                  time.Sleep(100 * time.Millisecond)
  
                  n,address, err := conn.ReadFromUDP(buf)
  
                  if err != nil {
                          fmt.Println("error reading data from connection")
                          fmt.Println(err)
                          return
                  }
  
                  if address != nil {
  
                          fmt.Println("got message from ", address, " with n = ", n)
  
                          if n &gt; 0 {
                                  fmt.Println("from address", address, "got message:", string(buf[0:n]), n)
                          }
                  }
          }
  
  }
  </code></pre>
  
  <p>client code, running on same server, with command <code>go run udp-client.go :1200</code> or <code>go run udp-client.go 127.0.0.1:1200</code></p>
  
  <pre><code>package main
  
  import (
  "fmt"
  "net"
  "os"
  "time"
  )
  
  func main() {
  
          if len(os.Args) != 2{
                  fmt.Fprintf(os.Stderr, "Usage:%s host:port", os.Args[0])
                  os.Exit(1)
          }
  
          service := os.Args[1]
  
          fmt.Println("Connecting to server at ", service)
  
          conn, err := net.Dial("udp",service)
  
          if err != nil {
                  fmt.Println("Could not resolve udp address or connect to it  on " , service)
                  fmt.Println(err)
                  return
          }
  
          fmt.Println("Connected to server at ", service)
  
          defer conn.Close()
  
          fmt.Println("About to write to connection")
  
          for {
  
                  time.Sleep(1000*time.Millisecond)
                  n, err := conn.Write([]byte("SOS ... \n"))
                  if err != nil {
                          fmt.Println("error writing data to server", service)
                          fmt.Println(err)
                          return
                  }
  
                  if n &gt; 0 {
                          fmt.Println("Wrote ",n, " bytes to server at ", service)
                  }
          }
  
  }
  </code></pre>