Skip to content

Add example of robust socket echo server #316

Open
@eliben

Description

@eliben

The net package has some good examples for writing socket servers, but it doesn't provide a full example for a robust echo server that reads all data from clients around errors and EOFs.

io.Reader's docs say:

When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (and n == 0) from a subsequent call. An instance of this general case is that a Reader returning a non-zero number of bytes at the end of the input stream may return either err == EOF or err == nil. The next Read should return 0, EOF.

This is something that's not hard to demonstrate with fairly little amount of code, and a robust socket echo server would make a good example.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions