O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The TCP server implementation works the same as the previous recipe, Creating the TCP server, from this chapter. The implementation is enhanced, with the ability to handle multiple clients simultaneously. Note that we are now handling the accepted connection in the separate goroutine. This means the server can continue to accept the client connections with the Accept method. 

Because the UDP protocol is not stateful and does not keep any connection, the handling of multiple clients is moved to application logic and you need to identify the clients and packet sequence. Only the writing response to a client could be parallelized with the use of goroutines.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required