Help

Make sure you can pass the Smoke Test. It is intended to highlight fundamental networking problems, so that you know you're starting from a good footing on the rest of the problems.

Make sure you've read the entire problem statement and you haven't missed anything. Read it out loud if it helps.

If your program seems to be working locally, check whether your router or firewall settings are blocking inbound connections. If they're allowing connections, try dumping a log of your program's exact network traffic and see if it looks right.

It's fine to look at the data being sent to your server to help yourself understand the protocol.

If you think everything looks good and you can't figure it out, feel free to email me on jes@protohackers.com and I'll try to help you, or ask in the Discord group.

Good luck!

Resources

Beej's Guide To Network Programming is a great introduction to network programming with C.

Netcat is a useful tool for testing your servers by hand.

Wireshark is a GUI tool for capturing & viewing network packets.

tcpdump is a command-line tool for capturing & viewing network packets.

The TCP RFCs are the source of ground truth on how TCP is supposed to work.

Examples

package main

import (
    "fmt"
    "io"
    "net"
    "os"
)

func main() {
    ln, err := net.Listen("tcp", ":10000")
    if err != nil {
        fmt.Println("listen: ", err.Error())
        os.Exit(1)
    }
    fmt.Println("listening on port 10000")
    for {
        conn, err := ln.Accept()
        if err != nil {
            fmt.Println("accept: ", err.Error())
            os.Exit(1)
        }
        fmt.Println("connection from ", conn.RemoteAddr())
        go handle(conn)
    }
}

func handle(conn net.Conn) {
    defer conn.Close()

    if _, err := io.Copy(conn, conn); err != nil {
        fmt.Println("copy: ", err.Error())
    }
}