Created
April 29, 2019 09:04
-
-
Save itzmeanjan/7288e0e9e1be4ae333a4f2761d156ffd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io' | |
show RawDatagramSocket, RawSocketEvent, InternetAddress, Datagram; | |
import 'dart:convert' show utf8; | |
main() => | |
// UDP server | |
RawDatagramSocket.bind(InternetAddress.anyIPv4, 8000) | |
.then((datagramSocket) { | |
datagramSocket.readEventsEnabled = true; | |
datagramSocket.listen((RawSocketEvent event) { | |
if (event == RawSocketEvent.read) { | |
Datagram dg = datagramSocket.receive(); | |
if (dg != null) { | |
datagramSocket.send(dg.data, dg.address, dg.port); | |
print('${dg.address}:${dg.port} -- ${utf8.decode(dg.data)}'); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment