blob: 3038560e820dc6f995fca37bda5d49a985a53dfc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include "bu/udpsocket.h"
#include "bu/sio.h"
#include <errno.h>
using namespace Bu;
int main( int argc, char *argv[] )
{
if( argv[1][0] == 'l' )
{
sio << "Listening..." << sio.nl;
Bu::UdpSocket udp( "255.255.255.255", 6688, UdpSocket::Read|UdpSocket::Broadcast );
for(;;)
{
char buf[1501];
int iRead = udp.read( buf, 1500 );
buf[iRead] = '\0';
sio << "Read(" << iRead << "): '" << buf << "'" << sio.nl;
}
}
else if( argv[1][0] == 'b' )
{
sio << "Broadcasting..." << sio.nl;
Bu::UdpSocket udp("255.255.255.255", 6688,
UdpSocket::Write|UdpSocket::Broadcast );
for(;;)
{
int iWrote = udp.write("hello", 5 );
sio << "Wrote(" << iWrote << "): " << strerror( errno ) << sio.nl;
usleep( 250000 );
}
}
else
{
sio << "Options are 'l' for listening and 'b' for broadcasting."
<< sio.nl;
}
return 0;
}
|