Skip to content

Conversation

@kavin81
Copy link

@kavin81 kavin81 commented Dec 30, 2025

  • this PR is for add an example #154
  • it's a simple hello-world example where if client sends "hello" -> server responds with "World!"
  • also just fixed a misc typo in comments

Copilot AI review requested due to automatic review settings December 30, 2025 06:31
@macroscopeapp
Copy link
Contributor

macroscopeapp bot commented Dec 30, 2025

Add a runnable helloWorld example with a WebTransport server on :4430 at path /webtransport, a CLI client using new common helpers, and a 1024-byte per-stream read limit

Introduce an examples module with a server and client demonstrating bidirectional streams, including self-signed TLS setup and an insecure client TLS config; update documentation and adjust the webtransport.Server ApplicationProtocols comment.

📍Where to Start

Start with the server entry point in main.go, then follow session handling in handleSession and per-stream logic in handleStream.


Macroscope summarized e5f4442.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a hello world example for the webtransport-go library and fixes a documentation URL in server.go. The example demonstrates basic bidirectional communication where a client can send messages to a server via WebTransport streams, with the server responding "world!" to "hello" messages.

  • Adds a complete hello world example with client, server, and shared configuration code
  • Includes comprehensive documentation with usage instructions and mermaid flowcharts
  • Updates the server.go comment to use a more specific URL format

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
server.go Updates documentation URL to use a more specific anchor link format
examples/go.mod Defines the Go module for examples with dependencies
examples/go.sum Contains checksums for example dependencies
examples/README.md Provides overview of available examples
examples/helloWorld/README.md Comprehensive documentation for the hello world example
examples/helloWorld/common/config.go Shared configuration including TLS setup and server settings
examples/helloWorld/server/main.go WebTransport server implementation
examples/helloWorld/client/main.go Interactive WebTransport client implementation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Server response: world!

Enter message: test
Server response: echo: test
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example output on line 42 shows "Server response: echo: test", but the actual server implementation (server/main.go line 75) sends "I only respond to 'hello' with 'world!'" for any non-"hello" message. The example output should match the actual server behavior.

Copilot uses AI. Check for mistakes.
Comment on lines 34 to 37
SerialNumber: big.NewInt(1),
NotBefore: time.Now(),
NotAfter: time.Now().Add(365 * 24 * time.Hour),
DNSNames: []string{"localhost"},
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self-signed certificate lacks required basic fields for x509.Certificate. The certificate should include KeyUsage and ExtKeyUsage fields to properly identify its purpose. Additionally, consider adding IsCA: false to explicitly indicate this is not a CA certificate.

Suggested change
SerialNumber: big.NewInt(1),
NotBefore: time.Now(),
NotAfter: time.Now().Add(365 * 24 * time.Hour),
DNSNames: []string{"localhost"},
SerialNumber: big.NewInt(1),
NotBefore: time.Now(),
NotAfter: time.Now().Add(365 * 24 * time.Hour),
DNSNames: []string{"localhost"},
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
IsCA: false,
BasicConstraintsValid: true,

Copilot uses AI. Check for mistakes.
func handleStream(stream *webtransport.Stream) {
defer stream.Close()

data, err := io.ReadAll(stream)
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using io.ReadAll on an incoming stream without any size limit or timeout can lead to resource exhaustion if a malicious client sends a very large message. Consider implementing a maximum message size limit or using io.LimitReader to protect against DoS attacks.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,86 @@
package server
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package declaration should be "main" instead of "server" for an executable program. Go programs that should be run with "go run" must be in package main with a main() function.

Suggested change
package server
package main

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,96 @@
package client
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package declaration should be "main" instead of "client" for an executable program. Go programs that should be run with "go run" must be in package main with a main() function.

Suggested change
package client
package main

Copilot uses AI. Check for mistakes.
B --> C[Connected!]
C --> D[Get User Input]
D --> E{quit?}
E -->|Yes| F[lose & Exit]
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo in the flowchart. "lose" should be "Close" to properly indicate "Close & Exit".

Suggested change
E -->|Yes| F[lose & Exit]
E -->|Yes| F[Close & Exit]

Copilot uses AI. Check for mistakes.

1. **Server** listens for WebTransport connections
2. **Client** connects and opens streams for each message
3. Server responds with "world!" for "hello", otherwise echoes the message
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README description on line 21 states the server "echoes the message" for non-"hello" messages, but the actual implementation in server/main.go (line 75) sends "I only respond to 'hello' with 'world!'" instead of echoing. The documentation should match the actual behavior.

Copilot uses AI. Check for mistakes.

```mermaid
flowchart TD
A[Start Server] --> B[Listen on :4433]
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The port number in the flowchart shows ":4433", but the actual server configuration in common/config.go uses port "4430" (line 15). The documentation should reflect the correct port number.

Suggested change
A[Start Server] --> B[Listen on :4433]
A[Start Server] --> B[Listen on :4430]

Copilot uses AI. Check for mistakes.
E --> F[Read Message]
F --> G{hello?}
G -->|Yes| H[Send: world!]
G -->|No| I[Send: echo message]
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flowchart description on line 59 shows "Send: echo message" which does not match the actual server implementation. The server sends "I only respond to 'hello' with 'world!'" for non-"hello" messages, not an echo of the message.

Copilot uses AI. Check for mistakes.
@kavin81
Copy link
Author

kavin81 commented Jan 2, 2026

@marten-seemann hi I'm sorry if your busy (rightfully so); TLDR in case you didnt see the PR / missed it - do you have any feedback on it?

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.

1 participant