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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access