Connecting to the remote server
TCP-based protocols are the most significant protocols used in network communication. Just as a reminder, HTTP, FTP, SMTP, and other protocols are part of this group. This recipe gives you an insight on how to connect to the TCP server in general.
How to do it...
- Open the console and create the folder
chapter07/recipe02
. - Navigate to the directory.
- Create the
tcpclient.go
file with the following content:
package main import ( "bufio" "context" "fmt" "io" "net" "net/http" "time" ) type StringServer string func (s StringServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { rw.Write([]byte(string(s))) } func createServer(addr string) http.Server { return http.Server{ Addr: addr, Handler: StringServer("HELLO GOPHER!\n"), } } ...