package main import ( "log" "net" "strconv" "strings" ) const ( message = "init http://localhost:8080/configuration.txt" StopCharacter = "\r\n\r\n" ) func SocketClient(ip string, port int) { addr := strings.Join([]string{ip, strconv.Itoa(port)}, ":") conn, err := net.Dial("tcp", addr) defer conn.Close() if err != nil { log.Fatalln(err) } conn.Write([]byte(message)) // conn.Write([]byte(StopCharacter)) log.Printf("Send: %s", message) buff := make([]byte, 1024) n, _ := conn.Read(buff) log.Printf("Receive from %v: %s", port, buff[:n]) } func main() { var ( ip = "127.0.0.1" portList = []int{3333, 4444} ) for _, port := range portList { SocketClient(ip, port) } }