this is a TCP server that writes a fixed string and then closes the connection, in order to investigate the behavior of netcat with respect to FIN packets
()
| 13 | // behavior of netcat with respect to FIN packets |
| 14 | |
| 15 | func Main() error { |
| 16 | var args struct { |
| 17 | Addr string `arg:"positional" default:":11223"` |
| 18 | } |
| 19 | arg.MustParse(&args) |
| 20 | |
| 21 | log.Printf("listening on %v ...", args.Addr) |
| 22 | l, err := net.Listen("tcp", args.Addr) |
| 23 | if err != nil { |
| 24 | return fmt.Errorf("error listening on %v: %w", args.Addr, err) |
| 25 | } |
| 26 | for { |
| 27 | conn, err := l.Accept() |
| 28 | if err != nil { |
| 29 | return err |
| 30 | } |
| 31 | |
| 32 | fmt.Fprintln(conn, "hello fin experiment") |
| 33 | conn.Close() |
| 34 | log.Printf("accepted and closed a connection from %v", conn.RemoteAddr()) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func main() { |
| 39 | log.SetOutput(os.Stdout) |
no test coverage detected