A concurrent TCP server

In this section, you will learn how to develop a concurrent TCP server using goroutines. For each incoming connection to the TCP server, the program will start a new goroutine to handle that request. This allows it to accept more requests, which means that a concurrent TCP server can serve multiple clients simultaneously.

The job of the TCP concurrent server is to accept a positive integer and return a natural number from the Fibonacci sequence. If there is an error in the input, the return value will be -1. As the calculation of numbers in the Fibonacci sequence can be slow, we are going to use an algorithm that was first presented in Chapter 11, Code Testing, Optimization, and Profiling, and was included in benchmarkMe.go ...

Get Mastering Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.