Created
April 29, 2019 09:12
-
-
Save itzmeanjan/280bb64b48878571b898c99f274ec8df 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 client | |
RawDatagramSocket.bind(InternetAddress.anyIPv4, 0).then((datagramSocket) { | |
datagramSocket.broadcastEnabled = true; | |
datagramSocket.readEventsEnabled = true; | |
datagramSocket.listen((RawSocketEvent event) { | |
if (event == RawSocketEvent.read) { | |
Datagram dg = datagramSocket.receive(); | |
if (dg != null) { | |
print('${dg.address}:${dg.port} -- ${utf8.decode(dg.data)}'); | |
//datagramSocket.close(); | |
} | |
} | |
}); | |
datagramSocket.send("io.github.itzmeanjan.transferZ".codeUnits, | |
InternetAddress("255.255.255.255"), 8000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment