Skip to content

Commit

Permalink
added options to allow testing udp multicast
Browse files Browse the repository at this point in the history
Signed-off-by: hayati ayguen <[email protected]>
  • Loading branch information
hayguen committed Aug 23, 2021
1 parent 9cbb2e7 commit 4936c87
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 9 additions & 1 deletion examples/TxToUdpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ int main(int argc, char **argv)

if ( argc < 3 )
{
fprintf(stderr, "usage: %s <host> <text> [<bind-address> <bind-port>]\n", argv[0] );
fprintf(stderr, "usage: %s <host> <text> [-m [<ttl>] | <bind-address> <bind-port>]\n", argv[0] );
fprintf(stderr, " -m : activate multicast on socket\n");
return 10;
}

Expand All @@ -34,6 +35,13 @@ int main(int argc, char **argv)
return 10;
}

if ( 3 < argc && !strcmp(argv[3], "-m") )
{
uint8 multicastTTL = ( 4 < argc ) ? atoi(argv[4]) : 1;
bool ret = socket.SetMulticast(true, 3);
fprintf(stderr, "Setting Multicast with TTL 3 %s\n", ret ? "was successful" : "failed");
}

fprintf(stderr, "\nLocal is %s. Local: %s:%u "
, ( socket.IsServerSide() ? "Server" : "Client" )
, socket.GetLocalAddr(), (unsigned)socket.GetLocalPort());
Expand Down
19 changes: 16 additions & 3 deletions examples/UdpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,33 @@ int main(int argc, char **argv)
CPassiveSocket passiveSocket( CSimpleSocket::SocketTypeUdp );

const char * bindAddr = 0;
const char * multicastGroup = 0;
unsigned bindPort = 6789;
bool bindRet;

if ( argc <= 1 )
fprintf(stderr, "usage: %s [<bind-address> [<bind-port>]]\n", argv[0] );
{
fprintf(stderr, "usage: %s [<bind-address> [<bind-port> [<multicast-group-ip>]]]\n", argv[0] );
fprintf(stderr, " do not use <bind-address> '127.0.0.1' if you want to accept reception from remotes\n");
fprintf(stderr, " suggestion for <multicast-group-ip>: 224.0.0.1\n");
}
if ( 1 < argc )
bindAddr = argv[1];
if ( 2 < argc )
bindPort = atoi(argv[2]) & 65535;
if ( 3 < argc )
multicastGroup = argv[3];

//--------------------------------------------------------------------------
// Initialize our socket object
//--------------------------------------------------------------------------
passiveSocket.Initialize();
fprintf(stderr, "binding to %s:%u\n", bindAddr, bindPort);
passiveSocket.Bind( bindAddr, uint16(bindPort) ); // not "127.0.0.1" to allow testing with remotes
if (!multicastGroup)
fprintf(stderr, "binding to %s:%u\n", bindAddr, bindPort);
else
fprintf(stderr, "binding to %s:%u for multicast-group %s\n", bindAddr, bindPort, multicastGroup);
bindRet = passiveSocket.BindMulticast( bindAddr, multicastGroup, uint16(bindPort) );
fprintf(stderr, "bind %s\n", bindRet ? "was successful" : "failed");
CSimpleSocket &socket = passiveSocket;

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

0 comments on commit 4936c87

Please sign in to comment.