Created
January 25, 2019 22:12
-
-
Save ultrasilicon/a58545f9fadc2c1698d9a507bc8c5309 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
#include <iostream> | |
#include <PUdpSocket.h> | |
#include <PTimer.h> | |
#include <PFunction.h> | |
using namespace std; | |
using namespace Parsley; | |
static Loop *loop; | |
static UdpSocket* server; | |
static Timer* timer; | |
static int counter = 0; | |
void send_cb(Timer *) | |
{ | |
if(counter == 100) | |
{ | |
timer->stop(); | |
server->stop(); | |
} | |
server->write("255.255.255.255", 66666, "hello: " + to_string(++ counter)); | |
} | |
void receive_cb(string& data, IPAddress ip) | |
{ | |
cout << ip.toIPString() << ": " << data << '\n'; | |
} | |
int main() | |
{ | |
loop = new Loop(); | |
server = new UdpSocket("0.0.0.0", 66666, loop); | |
connect(&server->onReadyRead, &receive_cb); | |
server->start(); | |
timer = new Timer(1, 5, loop); | |
connect(&timer->onTimedOut, &send_cb); | |
timer->start(); | |
return loop->run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment