Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of robust socket echo server #316

Open
eliben opened this issue Jan 11, 2020 · 2 comments
Open

Add example of robust socket echo server #316

eliben opened this issue Jan 11, 2020 · 2 comments

Comments

@eliben
Copy link
Collaborator

eliben commented Jan 11, 2020

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.

@Omid-SH
Copy link

Omid-SH commented Feb 3, 2021

Hi, I have prepared an answer to the problem, raised in the link below. Hope you enjoy it :)
316

@mmcgrana
Copy link
Owner

At a glance the linked example looks like it's headed in the right direction. An example would need to be edited for concision, style, and have commentary in line with the rest of the site, and be introduced as a PR against this repo. I don't personally have time to work on that right now, but if someone else does feel free to go for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants