4 hours ago · 10 min read1985 words · Tech · hide · 0 comments

This is part 8 in a series of posts on writing concurrent network servers. In this part, we'll switch to Go and see how it tackles the challenges described earlier in the series. All posts in the series: Part 1 - Introduction Part 2 - Threads Part 3 - Event-driven Part 4 - libuv Part 5 - Redis case study Part 6 - Callbacks, Promises and async/await Part 7 - Rust Part 8 - Go (this part) This post assumes a basic familiarity with the Go programming language. Sequential state machine server As before, we'll start with a sequential server for the basic state machine protocol presented in part 1. This is the main function: func main() { port := "9090" if len(os.Args) >= 2 { port = os.Args[1] } log.Println("Serving on port", port) listener, err := net.Listen("tcp", ":"+port) if err != nil { log.Fatal("Error listening:", err) } defer listener.Close() for { conn, err := listener.Accept() if err != nil { log.Printf("Error accepting connection: %v", err) continue } log.Println("connection…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.