Developing a simple TCP client
In this section, we will develop a TCP client named TCPclient.go. The port number the client will try to connect to as well as the server address will be given as command-line arguments to the program. The Go code of the TCP client will be presented in five parts; the first part is the following:
package main import ( "bufio" "fmt" "net" "os" "strings" )
The second part of TCPclient.go is the following:
func main() { 
   arguments := os.Args 
   if len(arguments) == 1 { 
         fmt.Println("Please provide host:port.") 
         os.Exit(100) 
   } The third part of TCPclient.go has the following Go code:
   CONNECT := arguments[1] 
   c, err := net.Dial("tcp", CONNECT) 
   if err != nil { 
         fmt.Println(err) 
         os.Exit(100) 
   } Once again, you use the net.Dial() function to try to connect to the desired port of the desired TCP server.
The fourth part of the TCP client is the following:
   for { 
         reader := bufio.NewReader... 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                 
        