You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solutions/gleam/02-rg2/config.yml
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ hints:
2
2
- title_markdown: "How do I access the client's TCP connection?"
3
3
body_markdown: |-
4
4
Use the [`handler()`](https://hexdocs.pm/glisten/glisten.html#handler) callbacks to access the client's connection:
5
-
5
+
6
6
```gleam
7
7
glisten.handler(
8
8
fn(_conn) { #(Nil, None) }, // Connection handler
@@ -11,18 +11,18 @@ hints:
11
11
}
12
12
)
13
13
```
14
-
14
+
15
15
The second callback receives messages from the client along with the `conn` (connection) parameter.n`.
16
16
- title_markdown: "How do I send a response to the client?"
17
17
body_markdown: |-
18
18
Use the [`send()`](https://hexdocs.pm/glisten/glisten.html#send) function to send a response to the client:
19
-
19
+
20
20
```gleam
21
21
import gleam/bytes_builder
22
-
22
+
23
23
let assert Ok(_) = glisten.send(conn, bytes_builder.from_string("+PONG\r\n"))
24
24
```
25
-
26
-
- Use `bytes_builder.from_string()` to convert the string to bytes.
25
+
26
+
- Use `bytes_builder.from_string()` to convert the string to bytes.
27
27
- `+PONG\r\n` is the string "PONG" encodedOptionalas a [RESP simple string](https://redis.io/docs/latest/develop/reference/protocol-spec/#simple-strings).
28
28
- Send the response inside the message handler (second callback), not the connection handler.
0 commit comments