In this section, you will learn how to develop a concurrent TCP server, using goroutines. For each incoming connection to the TCP server, the TCP server 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 of the Fibonacci sequence can be slow, we will use an algorithm that was first presented in Chapter 11, Code Testing, Optimization and Profiling, and was included in benchmarkMe.go
. Additionally, this time the algorithm used will be explained a bit further.
The name of the program is fiboTCP.go
, and its code is presented in five parts. As it is considered good practice to be able to define the port number of a web service as a command...