ProtoHackers Challenge
I was trying to get some hands-on experience coding some layer 4 level networking applications and while going through some project ideas, I stumbled upon protohackers challenge - a challenged which where you will have to create a server with non-convectional protocols, test them on variety of test case and then get a place on leaderboard.
Although this challenge is not actively posting new problems anymore, you can still post solutions and climb leaderboard and for my use case this was perfect.
Setup
Hosting
You are required to have a machine whose ip is visible to internet, and then this machine will be bombarded with request following specific protocol mentioned in challenge.
I had some GCP credit left and decided to explore options there. Eventually I stumbled upon e2 VMs which suits my requirement perfectly. With some firewall configuration, and using the lowest possible resource heavy e2 instance (1 shared cpu and 1 Gb memory), I was up and running
Now the usual flow was, just take the executable of server and upload this on this instance and start the server. You are given a public ip that you can just just input in protoHacker, and you are good to go.
Always remember to kill off these VMs as they can free up your free credit in no time.
Language
I decided to go barebone and not use any kind of framework, just plain Go. Its anyway not needed since we are only required to have functioning tcp server and in Go, you can get that with as concise snippet as this
func main() {
lis, err := net.Listen("tcp", "0.0.0.0:8080")
if err != nil {
panic(err)
}
host, port, err := net.SplitHostPort(lis.Addr().String())
fmt.Printf("Server Started at: %s:%s\n", host, port)
for {
conn, err := lis.Accept()
if err != nil {
panic(err)
}
go handle_connection(conn)
}
}
Spoiler - This is mostly the solution for first challenge, but that is the introduction challenge.
Solutions
I am yet to complete all the challenges, mainly because of my own procrastination, but for all the challenges, you can find the solution here. I have not yet added any kind of readme and don't intend to as well, and mainly want user to use this as reference