Skip to content

Commit cb1090c

Browse files
committed
Refactor hints in config files
1 parent 9fb2176 commit cb1090c

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

solutions/go/02-rg2/config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
hints:
22
- title_markdown: "How do I access the client's TCP connection?"
33
body_markdown: |-
4-
This is returned by the [`Accept()`](https://pkg.go.dev/net#Listener.Accept) method.
5-
4+
Use the [`Accept()`](https://pkg.go.dev/net#Listener.Accept) method on the listener to get the client connection:
65
```go
76
// The return value value includes:
87
// 1. the client's connection (a `net.Conn` object)
@@ -12,7 +11,7 @@ hints:
1211
1312
Each [`net.Conn`](https://pkg.go.dev/net#Conn) represents an active connection from a client.
1413
15-
- title_markdown: "How do I send a response to the client?"
14+
- title_markdown: 'How do I send a response to the client?'
1615
body_markdown: |-
1716
Use the [`Write()`](https://pkg.go.dev/net#Conn.Write) method on the client's connection:
1817

solutions/python/02-rg2/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
hints:
22
- title_markdown: "How do I access the client's TCP connection?"
33
body_markdown: |-
4-
This is returned by the [`accept()`](https://docs.python.org/3/library/socket.html#socket.socket.accept) method.
4+
Use the [`accept()`](https://docs.python.org/3/library/socket.html#socket.socket.accept) method to get the client connection:
55
66
```python
77
# The return value includes:
@@ -10,9 +10,9 @@ hints:
1010
connection, _ = server_socket.accept()
1111
```
1212
13-
The above code uses `_` to ignore the second return value, which is the client's address.
13+
The code above uses `_` to ignore the second return value, which is the client's address.
1414
15-
- title_markdown: "How do I send a response to the client?"
15+
- title_markdown: 'How do I send a response to the client?'
1616
body_markdown: |-
1717
Use the [`sendall()`](https://docs.python.org/3/library/socket.html#socket.socket.sendall) method on the client's connection:
1818
@@ -21,5 +21,5 @@ hints:
2121
connection.sendall(b"+PONG\r\n")
2222
```
2323
24-
- The above code uses `b` to create a [bytes object](https://docs.python.org/3/library/stdtypes.html#bytes).
24+
- The `b` prefix converts the string to a [bytes object](https://docs.python.org/3/library/stdtypes.html#bytes).
2525
- `+PONG\r\n` is the string "PONG" encoded as a [RESP simple string](https://redis.io/docs/latest/develop/reference/protocol-spec/#simple-strings).

solutions/rust/02-rg2/config.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
hints:
22
- title_markdown: "How do I access the client's TCP connection?"
33
body_markdown: |-
4-
This is returned by the [`incoming()`](https://doc.rust-lang.org/std/net/struct.TcpListener.html#method.incoming) method.
4+
Use the [`incoming()`](https://doc.rust-lang.org/std/net/struct.TcpListener.html#method.incoming) method on the listener to get the client connection:
55
66
```rust
77
// The return value is an iterator that provides a sequence of `TcpStream` objects.
8-
for stream in listener.incoming()
8+
for stream in listener.incoming() {
9+
match stream {
10+
Ok(mut stream) => {
11+
// Handle the connection here
12+
}
13+
Err(e) => {
14+
println!("Error: {}", e);
15+
}
16+
}
17+
}
918
```
1019
1120
Each [`TcpStream`](https://doc.rust-lang.org/std/net/struct.TcpStream.html) represents an active connection from a client.
1221
13-
- title_markdown: "How do I send a response to the client?"
22+
- title_markdown: 'How do I send a response to the client?'
1423
body_markdown: |-
1524
Use the [`write_all()`](https://doc.rust-lang.org/std/io/trait.Write.html#method.write_all) method on the client's connection:
1625
1726
```rust
27+
use std::io::Write;
28+
29+
// Inside your match Ok(mut stream) => { ... } block
1830
// Send the response to the client
1931
stream.write_all(b"+PONG\r\n").unwrap();
2032
```
2133
22-
- The above code uses `b` to create a [byte string literal](https://doc.rust-lang.org/reference/tokens.html#byte-string-literals).
34+
- To use `write_all()`, you need to import the [Write](https://doc.rust-lang.org/std/io/trait.Write.html) trait and mark the `TcpStream` as [mutable](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html).
35+
- The `b` prefix converts the string to a [byte string literal](https://doc.rust-lang.org/reference/tokens.html#byte-string-literals).
2336
- `+PONG\r\n` is the string "PONG" encoded as a [RESP simple string](https://redis.io/docs/latest/develop/reference/protocol-spec/#simple-strings).
24-
- To satisfy the Rust compiler, you also need to import the [Write](https://doc.rust-lang.org/std/io/trait.Write.html) trait and mark the TcpStream as [mutable](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html) in order to use `write_all()`.

0 commit comments

Comments
 (0)