diff options
Diffstat (limited to '')
-rw-r--r-- | src/tests/udpsocket.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/tests/udpsocket.cpp b/src/tests/udpsocket.cpp new file mode 100644 index 0000000..63aa576 --- /dev/null +++ b/src/tests/udpsocket.cpp | |||
@@ -0,0 +1,41 @@ | |||
1 | #include "bu/udpsocket.h" | ||
2 | #include "bu/sio.h" | ||
3 | |||
4 | using namespace Bu; | ||
5 | |||
6 | int main( int argc, char *argv[] ) | ||
7 | { | ||
8 | if( argv[1][0] == 'l' ) | ||
9 | { | ||
10 | sio << "Listening..." << sio.nl; | ||
11 | Bu::UdpSocket udp( "255.255.255.255", 6688, UdpSocket::Read|UdpSocket::Broadcast ); | ||
12 | |||
13 | for(;;) | ||
14 | { | ||
15 | char buf[1501]; | ||
16 | int iRead = udp.read( buf, 1500 ); | ||
17 | buf[iRead] = '\0'; | ||
18 | sio << "Read(" << iRead << "): '" << buf << "'"; | ||
19 | } | ||
20 | } | ||
21 | else if( argv[1][0] == 'b' ) | ||
22 | { | ||
23 | sio << "Broadcasting..." << sio.nl; | ||
24 | Bu::UdpSocket udp("255.255.255.255", 6688, | ||
25 | UdpSocket::Write|UdpSocket::Broadcast ); | ||
26 | |||
27 | for(;;) | ||
28 | { | ||
29 | udp.write("hello", 5 ); | ||
30 | usleep( 250000 ); | ||
31 | } | ||
32 | } | ||
33 | else | ||
34 | { | ||
35 | sio << "Options are 'l' for listening and 'b' for broadcasting." | ||
36 | << sio.nl; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||