Skip to content

Commit

Permalink
fixup! feat: add experimental CoAP server implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Oct 30, 2022
1 parent dba7547 commit 5d24d49
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/src/coap_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class _CoapUdpServer extends CoapServer {
final message = CoapMessage.fromUdpPayload(data);
if (message is CoapRequest && !message.hasFormatError) {
if (message.hasUnknownCriticalOption) {
_rejectMessage(message, datagram.address, datagram.port);
_rejectRequest(message, datagram.address, datagram.port);
return;
}
message
Expand Down Expand Up @@ -157,15 +157,23 @@ class _CoapUdpServer extends CoapServer {
final InternetAddress address,
final int port,
) {
_socket.send(response.toUdpPayload().toList(), address, port);
_send(response, address, port);
}

void _rejectMessage(
void _rejectRequest(
final CoapRequest request,
final InternetAddress address,
final int port,
) {
final resetMessage = CoapEmptyMessage.newRST(request);
_send(resetMessage, address, port);
}

void _send(
final CoapMessage message,
final InternetAddress address,
final int port,
) {
final resetMessage = CoapEmptyMessage.newRST(message);
_socket.send(resetMessage.toUdpPayload().toList(), address, port);
_socket.send(message.toUdpPayload().toList(), address, port);
}
}

0 comments on commit 5d24d49

Please sign in to comment.