-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Added TCP and UDP examples on Socket Programming #631
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
Added TCP and UDP examples on Socket Programming #631
Conversation
| @@ -0,0 +1,173 @@ | |||
| // Socket programming allows direct communication between | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need for these two long paragraphs explaining what TCP is. Let's assume the reader knows, and just wants to learn how to do this in Go
| // If there's an error accepting (e.g., the | ||
| // listener was closed), log it and continue | ||
| // accepting other connections. | ||
| fmt.Println("Error accepting connection:", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that CI fails on this line because it's too long
You have to run tools/build locally to ensure a successful build. This will also create the output files you can add to the PR
| // Accept connections in a loop. Each connection | ||
| // represents a client connecting to the server. | ||
| // This is a blocking call - the server will wait | ||
| // here until a client connects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly repeated below, one comment for Accept is enough
|
|
||
| // Handle each connection in a goroutine to allow | ||
| // the server to accept multiple clients concurrently. | ||
| // Without goroutines, the server would only be able |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part "Without goroutines" is unnecessary, goroutines were covered already
| } | ||
| } | ||
|
|
||
| // The TCP client connects to a server and sends data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this sample is too busy, seems like much larger than other samples.
Maybe the client and server should be separated? netcat can be used for testing, like curl is for the HTTP server example
Description
Added TCP and UDCP examples on Socket Programming
Testing
Checklist
examples.txt*.sh) are included with expected outputFixes #619