mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-24 11:54:49 +00:00
Handle MG_EV_CLOSE in examples
PUBLISHED_FROM=57c62a4123a54ecb455dbf91f3fe562fb0cf2ec2
This commit is contained in:
1 parent
e99088348d
commit
e62dc8f3b2
5 files changed
+34
-5
No files matched your search
@@ -7,10 +7,10 @@ To create a CoAP client, follow this pattern:
|
||||
1. Create an outbound connection by calling `mg_connect`
|
||||
2. Call `mg_set_protocol_coap` for created connection
|
||||
3. Create an event handler function that handles the following events:
|
||||
- `MG_EV_COAP_CON`
|
||||
- `MG_EV_COAP_NOC`
|
||||
- `MG_EV_COAP_ACK`
|
||||
- `MG_EV_COAP_RST`
|
||||
- `MG_EV_COAP_CON`
|
||||
- `MG_EV_COAP_NOC`
|
||||
- `MG_EV_COAP_ACK`
|
||||
- `MG_EV_COAP_RST`
|
||||
|
||||
Here's an example of the simplest CoAP client.
|
||||
Error checking is omitted for the sake of clarity:
|
||||
@@ -39,6 +39,13 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
|
||||
s_time_to_exit = 1;
|
||||
break;
|
||||
}
|
||||
case MG_EV_CLOSE: {
|
||||
if (s_time_to_exit == 0) {
|
||||
printf("Server closed connection\n");
|
||||
s_time_to_exit = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user