Skip to content

Conversation

@0xprincedev
Copy link

@0xprincedev 0xprincedev commented Nov 5, 2025

Description

Added TCP and UDCP examples on Socket Programming

Testing

  • Code compiles without errors
  • Examples follow the project's format and style
  • Comments are comprehensive and educational
  • Shell scripts demonstrate expected output
  • Tested examples run successfully

Checklist

  • Examples use only the standard library
  • Code follows Go conventions and project style
  • Comments explain concepts clearly for beginners
  • Examples are added to examples.txt
  • Shell scripts (*.sh) are included with expected output
  • No linter errors

Fixes #619

@@ -0,0 +1,173 @@
// Socket programming allows direct communication between
Copy link
Collaborator

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)
Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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.
Copy link
Collaborator

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Adding example on Socket Programming

2 participants