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 could be created using the net package. The net package contains the Listen function that creates the TCPListener, which can Accept the client connections. The Accept method calls on the TCPListener blocks until the client connection is received. If the client connection comes, the Accept method returns the TCPConn connection. The TCPConn is a connection to the client that serves to read and write data.

The TCPConn implements the Reader and Writer interfaces. All the approaches to write and read the data could be used. Note that there is a delimiter character for reading the data, otherwise, the EOF is received if the client forcibly closes the connection.

Note that this implementation handles only one client ...

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