Joining a multicast group

Login to reply to this topic.
Wed, 2006-01-25 15:42
Joined: 2005-11-10
Forum posts: 7
Hi,

I'm trying to get the emulator (S60v21)  to accept multicast messages that is being broadcast on the network. The emulator is connected to the network through the standard ethernet interface.

I'm using the following code:

   TInetAddr localAddress;
   localAddress.SetAddress(KInetAddrAny);
   localAddress.SetPort(9999);
   
   
   TInetAddr broadcast;
   broadcast.SetAddress(INET_ADDR(224,7,8,9));
   broadcast.SetPort(9999);
   broadcast.ConvertToV4Mapped();

   TRequestStatus status;

   User::LeaveIfError(client.Open(server,KAfInet,KSockDatagram,KProtocolInetUdp));
   User::LeaveIfError(client.Bind(localAddress));
   
   TIp6Mreq req;      
   
   req.iAddr = broadcast.Ip6Address();
   req.iInterface = 0;

   TPckgBuf<TIp6Mreq> pckg(req);      
   User::LeaveIfError(client.SetOpt(KSoIp6JoinGroup,KSolInetIp,pckg));

The call to SetOpt however always leaves with a -1 (KErrNotFound ) error code.
From what I understand, the Ip6 bits in some of the names refers to options available in the IPv4/IPv6 dual stack. Now I'm not sure whether some of these options is supported on the SDK version I'm using as some of the comments in in_sock.h like KSoIp6JoinGroup / LeaveGroup is marked as /** For future use.
I suspect that is probably why I'm getting the errors I'm getting, however any pointers in getting the multicast receiving client working would be greatly appreciated.

Thanks.


Wed, 2006-01-25 18:24
Joined: 2005-02-18
Forum posts: 100
Re: Joining a multicast group
Your problem is at least partly due to fact that you declare two TIp6Mreq structures, initialize one and then use the unitialized one...

Code:
  TIp6Mreq req;  // <--- 1st instance.
   req.iAddr = broadcast.Ip6Address();
   req.iInterface = 0;
   TPckgBuf<TIp6Mreq> pckg(req); // <-- 2nd instance
Might work with
Code:
TPckg<TIp6Mreq> pckg(req);
or, in your version, doing the init correctly:
Code:
  pckg().iAddr = ..
  pckg().iInterface = ..


...addendum: actually, your second instance should have been copied from the first, if I understand the TckgBuf correctly. I don't know what is wrong then. Non-Zero interface index might help, but finding that might be tricky sometimes.
Thu, 2006-01-26 08:51
Joined: 2005-11-10
Forum posts: 7
Re: Joining a multicast group
Thanks for the help, I've modified the TPckgBuf as you suggested, however I don't think that's the issue.
I'll give it another bash with different interface index numbers (I think 0 meant it should try and determine the interface automatically) and if that fails will try one of the newer SDK versions.

Thanks again for the help.
Thu, 2006-01-26 09:28
Joined: 2005-08-22
Forum posts: 3
Re: Joining a multicast group
Hi

I think the code is fine. The index, 0, is also fine. But you must start the connection first (see RConnection,  Start() method). At least on S60 v 3.0 BETA the code below works for us (eg with mcast address 225.0.0.52) as long as it is called after opening the socket and after RConnection.Start() has returned (we call it inside a RunL() method as we use the async version of Start() ):

TInt JoinMulticastGroup(TInetAddr& aAddr, RSocket& aSocket)
   {      
   TPckgBuf<TIp6Mreq> mReq;
   
   if (aAddr.Family() != KAfInet6)
      {
      aAddr.ConvertToV4Mapped();   
      }
      
   mReq().iAddr =  aAddr.Ip6Address();
   mReq().iInterface = 0;
   
   aSocket.SetOpt(KSoIp6MulticastHops, KSolInetIp, 10); //default is 1
   TInt err = aSocket.SetOpt(KSoIp6JoinGroup, KSolInetIp, mReq);
   
   
   //aSocket.SetOpt(KSoIp6MulticastLoop, KSolInetIp, ETrue);
   return err;
   }

I don't think the KSoIp6MulticastHops above is needed, we probably just forgot to remove it from our code, I left it there just in case.

Hope this helps,

Stefania
Thu, 2006-01-26 10:57
Joined: 2005-11-10
Forum posts: 7
Re: Joining a multicast group
Thanks Stefi, I wasn't aware that I needed to manually start the connection but it makes sense.

I've added the code to start a connection and interact with it a bit just to see it's working but it still doesn't like the idea of joining the multicast group :S

I'm busy downloading the v3.0 Beta SDK now to test it there. This snippet from the in_sock.h don't bode well for getting this to work on v2.1:

/** For future use.
*
* Uses TIp6Mreq structure. */
const TUint KSoIp6JoinGroup   = 0x46d; // ///< Set - Join multicast group (paramerer is TIp6Mreq)

Below is the code I'm testing with now with a synchronous RConnection start added and the multicast hops for good measure Tongue

Once I've tested on a newer SDK will let you know if it worked.

RSocketServ server;
   RSocket listener;
   RSocket client;
   
   // Connect Server
   User::LeaveIfError(server.Connect());
   
   // Start Connection - Can see ethernet init happening succesfully etc
   RConnection connection;
   User::LeaveIfError(connection.Open(server,KConnectionTypeDefault));
   User::LeaveIfError(connection.Start());

   // Number of connections returns 1 as expected
   TUint numberOfConnections;
   User::LeaveIfError(connection.EnumerateConnections(numberOfConnections));
   
   TPckgBuf<TConnectionInfo> connInfo;
   User::LeaveIfError(connection.GetConnectionInfo(numberOfConnections,connInfo));   

   // Listen on port 9999 which is where the udp multicast is happening
   TInetAddr localAddress;
   localAddress.SetAddress(KInetAddrAny);
   localAddress.SetPort(9999);
   
   User::LeaveIfError(client.Open(server,KAfInet,KSockDatagram,KProtocolInetUdp));
   User::LeaveIfError(client.Bind(localAddress));
   
   // Theoretically join mulicast group Tongue
   TInetAddr broadcast;
   broadcast.SetAddress(INET_ADDR(224,7,8,9));
   broadcast.SetPort(9999);

   if(broadcast.Family() != KAfInet6)
      broadcast.ConvertToV4Mapped();

   TPckgBuf<TIp6Mreq> req;
   req().iAddr = broadcast.Ip6Address();
   req().iInterface = 0;   
   
   User::LeaveIfError(client.SetOpt(KSoIp6MulticastHops, KSolInetIp, 10));
   User::LeaveIfError(client.SetOpt(KSoIp6JoinGroup,KSolInetIp,req)); // Leaves with -1


Thu, 2006-01-26 11:36
Joined: 2005-08-22
Forum posts: 3
Re: Joining a multicast group
Two more things that may be relevant:-

1) We open the socket by specifying the connection (probably not important):

User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection));   

2) We don't bind the socket, we only set the port number and also specify KSoReuseAddr:

iSocket.SetOpt(KSoReuseAddr, KProtocolInetIp, 1);
iSocket.SetLocalPort(iLocalPort);

//then join  multicast group
Thu, 2006-01-26 12:00
Joined: 2005-11-10
Forum posts: 7
Re: Joining a multicast group
Thanks again for your time Stefi.

I modified the code to :

User::LeaveIfError(client.Open(server,KAfInet,KSockDatagram,KProtocolInetUdp,connection));
   //User::LeaveIfError(client.Bind(localAddress));
   User::LeaveIfError(client.SetOpt(KSoReuseAddr,KProtocolInetIp,1));
   User::LeaveIfError(client.SetLocalPort(9999));

   
   // Theoretically join mulicast group Tongue
   TInetAddr broadcast;
   broadcast.SetAddress(INET_ADDR(224,7,8,9));
   broadcast.SetPort(9999);

   if(broadcast.Family() != KAfInet6)
      broadcast.ConvertToV4Mapped();

   TPckgBuf<TIp6Mreq> req;
   req().iAddr = broadcast.Ip6Address();
   req().iInterface = 0;   
   
   User::LeaveIfError(client.SetOpt(KSoIp6MulticastHops, KSolInetIp, 10));
   User::LeaveIfError(client.SetOpt(KSoIp6JoinGroup,KSolInetIp,req)); // Leaves with -1
   

Still getting the same error on the emulator, however I packaged it up and deployed to my Nokia 6680 (OS v8.0) and the code executed without problem. So my feeling is that joining a multicast group is not supported on OS v7.

Thanks again msa2 and stefi for the help.

Thu, 2006-06-08 11:49
Joined: 2003-11-06
Forum posts: 6
Re: Joining a multicast group
Has anybody found a way to do multicast-join on OS v7 or is it impossible?

Code:
client.SetOpt(KSoIp6JoinGroup,KSolInetIp,req)
returns -5 (KErrNotSupported) for me.

Mon, 2006-06-19 06:18
Joined: 2006-06-19
Forum posts: 5
Re: Joining a multicast group
Quote from: bjnkrm
Has anybody found a way to do multicast-join on OS v7 or is it impossible?

Code:
client.SetOpt(KSoIp6JoinGroup,KSolInetIp,req)
returns -5 (KErrNotSupported) for me.
I'm having the same problem with OS v9.1. Anyone solved this?
Tue, 2006-06-20 06:26
Joined: 2005-02-18
Forum posts: 100
Re: Joining a multicast group
The multicast is surely supported in 9.1 (and even in 7, if it has the IPv6 stack). The only possible cause for "not supported error" that I can think of are:

- some subtle error in application (socket not really opened to TCPIP or something),

- on emulator, use of some RSocket replacement library, which does not support all the features that real stack does

For -1 error, it basicly means that stack cannot find any active interface with multicast capability.
Tue, 2006-06-20 13:54
Joined: 2006-06-19
Forum posts: 5
Re: Joining a multicast group
Code:
RSocketServ server;
RSocket socket;
User::LeaveIfError( server.Connect() );

// RConnection
RConnection connection;
User::LeaveIfError( connection.Open( server, KConnectionTypeDefault ) );
User::LeaveIfError( connection.Start() ); // crashes here...

TUint numberOfConnections;
User::LeaveIfError( connection.EnumerateConnections(numberOfConnections) );
TPckgBuf<TConnectionInfo> connInfo;
User::LeaveIfError( connection.GetConnectionInfo(numberOfConnections,connInfo) );

// RSocket
User::LeaveIfError( socket.Open( server, KAfInet, KSockDatagram, KProtocolInetUdp, connection ) );
// User::LeaveIfError( socket.Open( server, KAfInet, KSockDatagram, KProtocolInetUdp) );
User::LeaveIfError( socket.SetOpt( KSoReuseAddr, KProtocolInetIp, 1 ) );
User::LeaveIfError( socket.SetLocalPort( 9000 ) );

// Multicast
TInetAddr multiAddr;
multiAddr.SetAddress( INET_ADDR(224,7,8,9) );
multiAddr.SetPort( 9000 );

if ( multiAddr.Family() != KAfInet6 ) {
multiAddr.ConvertToV4Mapped();
}

TPckgBuf< TIp6Mreq > req;
req().iAddr = multiAddr.Ip6Address();
req().iInterface = 0;

User::LeaveIfError( socket.SetOpt( KSoIp6JoinGroup, KSolInetUdp, multiAddr ) ); // or here
If I take RConnection part away then it crashes on KSoIp6JoinGroup and if I don't on RConnection.Start()

Using symbian os v9.1. Anyone get this code working?
Fri, 2006-06-23 18:26
Joined: 2005-02-18
Forum posts: 100
Re: Joining a multicast group
Crashes? Or do you just get error return, and when your code does the leave (as you have requested with LeaveIfError), it does not trap it correct?

Anyway, if RConnection::Start "crashes", then your problem has nothing to do with multicast.

Hmm.. did 9.1 have the capabilities already? Multicast join may require "Network Services" capabilitiy...
Mon, 2006-06-26 06:12
Joined: 2006-06-19
Forum posts: 5
Re: Joining a multicast group
Quote from: msa2
Crashes? Or do you just get error return, and when your code does the leave (as you have requested with LeaveIfError), it does not trap it correct?
Sorry, Leaves with code -1 or -5.
Quote
Anyway, if RConnection::Start "crashes", then your problem has nothing to do with multicast.
That i figured out myself but what am I doing wrong with the RConnect then?
Quote
Hmm.. did 9.1 have the capabilities already? Multicast join may require "Network Services" capabilitiy...
Network Services?
Mon, 2006-06-26 21:27
Joined: 2005-02-18
Forum posts: 100
Re: Joining a multicast group
Quote
Network Services?

Your application needs the "Network Services" capability to commucate out of the box in new OS releases with capability system active (mulicast join itself does not need that -- I remembered wrong).

In earlier message I asked about RSocket replacement libraries on emulator. You are surely not using any of those, like winsock.prt? Multicast join works only with the real Symbian TCP/IP stack.
Tue, 2006-06-27 08:57
Joined: 2006-06-19
Forum posts: 5
Re: Joining a multicast group
Quote from: msa2
Quote
Network Services?

Your application needs the "Network Services" capability to commucate out of the box in new OS releases with capability system active (mulicast join itself does not need that -- I remembered wrong).

In earlier message I asked about RSocket replacement libraries on emulator. You are surely not using any of those, like winsock.prt? Multicast join works only with the real Symbian TCP/IP stack.
Well, I haven't "modified" sdk. All the libraries that I'm using came with the SDK. I have linked insock.lib and esock.lib librarys and included <es_sock.h> and <in_sock.h>.

So how can I get real symbian TCP/IP stack?
Wed, 2006-08-09 12:07
Joined: 2006-06-19
Forum posts: 5
Re: Joining a multicast group
I got Nokia E70 phone where I tested my application. Still the same error KErrNotSupported (-5) when trying to set KSoIp6JoinGroup option.

Edit: Network Services capability has been set.
  • Login to reply to this topic.