Skip to content

Commit 7ff9952

Browse files
committed
added options to allow testing udp multicast
Signed-off-by: hayati ayguen <[email protected]>
1 parent 9cbb2e7 commit 7ff9952

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

examples/TxToUdpServer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ int main(int argc, char **argv)
3434
return 10;
3535
}
3636

37+
if ( 3 < argc && !strcmp(argv[3], "-m") )
38+
{
39+
uint8 multicastTTL = 3;
40+
bool ret = socket.SetMulticast(true, 3);
41+
fprintf(stderr, "Setting Multicast with TTL 3 %s\n", ret ? "was successful" : "failed");
42+
}
43+
3744
fprintf(stderr, "\nLocal is %s. Local: %s:%u "
3845
, ( socket.IsServerSide() ? "Server" : "Client" )
3946
, socket.GetLocalAddr(), (unsigned)socket.GetLocalPort());

examples/UdpServer.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,34 @@ int main(int argc, char **argv)
99
CPassiveSocket passiveSocket( CSimpleSocket::SocketTypeUdp );
1010

1111
const char * bindAddr = 0;
12+
const char * multicastGroup = 0;
1213
unsigned bindPort = 6789;
14+
bool bindRet;
15+
1316
if ( argc <= 1 )
14-
fprintf(stderr, "usage: %s [<bind-address> [<bind-port>]]\n", argv[0] );
17+
fprintf(stderr, "usage: %s [<bind-address> [<bind-port> [<multicast-group-ip>]]]\n", argv[0] );
1518
if ( 1 < argc )
1619
bindAddr = argv[1];
1720
if ( 2 < argc )
1821
bindPort = atoi(argv[2]) & 65535;
22+
if ( 3 < argc )
23+
multicastGroup = argv[3];
1924

2025
//--------------------------------------------------------------------------
2126
// Initialize our socket object
2227
//--------------------------------------------------------------------------
2328
passiveSocket.Initialize();
24-
fprintf(stderr, "binding to %s:%u\n", bindAddr, bindPort);
25-
passiveSocket.Bind( bindAddr, uint16(bindPort) ); // not "127.0.0.1" to allow testing with remotes
29+
if (!multicastGroup)
30+
{
31+
fprintf(stderr, "binding to %s:%u\n", bindAddr, bindPort);
32+
bindRet = passiveSocket.Bind( bindAddr, uint16(bindPort) ); // not "127.0.0.1" to allow testing with remotes
33+
}
34+
else
35+
{
36+
fprintf(stderr, "binding to %s:%u for multicast-group %s\n", bindAddr, bindPort, multicastGroup);
37+
bindRet = passiveSocket.BindMulticast( bindAddr, multicastGroup, uint16(bindPort) );
38+
}
39+
fprintf(stderr, "bind %s\n", bindRet ? "was successful" : "failed");
2640
CSimpleSocket &socket = passiveSocket;
2741

2842
fprintf(stderr, "\nLocal is %s. Local: %s:%u "

0 commit comments

Comments
 (0)