protohackers/cmd/smoketest/main.go

41 lines
533 B
Go

package main
import (
"fmt"
"io"
"log"
"net"
"os"
)
const (
connPort = "3030"
connType = "tcp4"
)
func main() {
l, err := net.Listen(connType, ":"+connPort)
if err != nil {
log.Fatalln(err)
os.Exit(1)
}
defer l.Close()
fmt.Println(fmt.Sprintf("Listening on port %s", connPort))
for {
conn, err := l.Accept()
if err != nil {
log.Fatalln(err)
}
go handleRequest(conn)
}
}
func handleRequest(conn net.Conn) {
defer conn.Close()
if _, err := io.Copy(conn, conn); err != nil {
log.Fatalln(err)
}
}