Re: WSASocket FAILS for multicast options..

From: Paul G. Tobey [eMVP] (ptobey_no_spam_at_instrument_no_spam.com)
Date: 05/21/04


Date: Fri, 21 May 2004 08:19:06 -0700

Yes, CE supports multicasting using Berkeley calls. Here's some code that I
pulled from an IP multicast test I've used on our devices:

 // Initialize Winsock.
 if (WSAStartup (MAKEWORD(1,1), &WSAData) != 0)
 {
  wsprintf (szError, TEXT("WSAStartup failed! Error: %d"),
      WSAGetLastError ());
  MessageBox (NULL, szError, TEXT("Error"), MB_OK);
  return FALSE;
 }

 // Set up the socket. We aren't associated with a multicast
 // group, after this, but the socket will be ready to be
 // associated.
 if ((Sock = socket (AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET)
 {
  wsprintf (szError, TEXT("Allocating socket failed! Error: %d"),
      WSAGetLastError ());
  MessageBox (NULL, szError, TEXT("Error"), MB_OK);
  return FALSE;
 }

 // Fill out the local socket's address information.
 local_sin.sin_family = AF_INET;
 local_sin.sin_port = htons (DEST_PORT);
 local_sin.sin_addr.s_addr = htonl (INADDR_ANY);

 // Associate the local address with Sock.
 if (bind (Sock,
  (struct sockaddr FAR *) &local_sin,
  sizeof (local_sin)) == SOCKET_ERROR)
 {
  wsprintf (szError, TEXT("Binding socket failed! Error: %d"),
      WSAGetLastError ());
  MessageBox (NULL, szError, TEXT("Error"), MB_OK);
  closesocket (Sock);
  return FALSE;
 }

 // ... The socket is now ready to be associated.

And here's the code that joins a group:

  mreq.imr_multiaddr.s_addr = inet_addr( joinIPs );
  mreq.imr_interface.s_addr = INADDR_ANY;

  if (setsockopt (Sock,
   IPPROTO_IP,
   IP_ADD_MEMBERSHIP,
   (char FAR *)&mreq,
   sizeof (mreq)) == SOCKET_ERROR)
  {
   wsprintf (szError, TEXT("setsockopt (join) failed! Error: %d"),
       WSAGetLastError ());
   MessageBox (NULL, szError, TEXT("Error"), MB_OK);
  }

That's about all there is to it...

There are a number of messages in the archives about "multicast". You can
search via Google from this link:

http://groups.google.com/groups?hl=en&group=microsoft.public.windowsce

Paul T.

"JNH" <anonymous@discussions.microsoft.com> wrote in message
news:1001601c43ed3$c91e8a60$a501280a@phx.gbl...
> Paul,
>
> Thanks for the reply. Not quite what I expected though.
>
> The following isn't aimed at you Paul, just another rant
> at MS!
>
> If these methods do not 'generally' work, why on earth
> are they included in the SDK with full Help
> documentation! Nowhere in the Help files is there any
> mension of 'not working' in CE! Seems like I've just
> wasted a lot of time chasing throught this! Thanks
> Microsoft!
>
> One question,does CE support mulicasting using Berkley
> style calls?
>
> JNH
>
> >-----Original Message-----
> >I don't know specifically about WSASocket, but,
> generally, the WSA socket
> >calls don't work on Windows CE. You need to use the
> Berkeley sockets calls
> >themselves, instead (socket(), bind(), ioctlsocket(),
> etc.)
> >
> >Paul T.
> >
> >"JNH" <anonymous@discussions.microsoft.com> wrote in
> message
> >news:f84701c43e37$e0bc0b80$a601280a@phx.gbl...
> >> Hi,
> >>
> >> I've written a small multicast app which works fine on
> my
> >> desktop PC. However, when I ported it to WinCE, eVC
> 4.0,
> >> I ran into trouble. According to the WinCE doc's there
> >> does not seem to be any difference between Winsock 2.0
> >> for PC and WinCE.
> >>
> >> Here's the code that fails :-
> >>
> >> DWORD dwFlags = WSA_FLAG_MULTIPOINT_C_LEAF |
> >> WSA_FLAG_MULTIPOINT_D_LEAF;
> >>
> >> m_pProvider = WSASocket(AF_INET, SOCK_DGRAM,
> IPPROTO_UDP,
> >> NULL, 0, dwFlags);
> >>
> >> WSAStartup succeeds but the subsequent call to
> WSASocket
> >> fails with an error of WSAEINVAL.
> >>
> >> Using a value of 0 for dwFlags executes OK but I cannot
> >> use the socket for multicast.....
> >>
> >> The very same code is fine under Visual Studio.NET on
> my
> >> PC but not on my CE device.... Why????????? :-(
> >>
> >> Anyone got any ideas?
> >>
> >> Thanks
> >>
> >> JNH
> >>
> >>
> >
> >
> >.
> >



Relevant Pages

  • Re: WSASocket FAILS for multicast options..
    ... Way ahead of you there Paul. ... I can send multicast messages but I can't ... > WSAGetLastError ); ... > wsprintf (szError, TEXT("Allocating socket failed! ...
    (microsoft.public.windowsce.app.development)
  • Re: socket question: how to use sendto and recvfrom based on the same multicast address
    ... Why don't you just use the same socket for both send and receive? ... multicast address and receive other data from others on the samd ... closesocket; ... if (setsockopt (sockrcv, ...
    (microsoft.public.windowsce.platbuilder)
  • AF_IPN: Inter Process Networking, try these...
    ... If you suspect we would be better using IP multicast, ... Exercise #1. ... I Create a IPN socket, with protocol IPN_VDESWITCH and all the VM can ... or a binary stream. ...
    (Linux-Kernel)
  • Re: !EventConnect Problem
    ... Paul T. ... The socket is not in a listening state. ... The incoming connection queue has no room for connections. ...
    (microsoft.public.windowsce.app.development)
  • Re: Too much multicasting in Linux
    ... > that didn't join the multicast address where the data is being sent. ... > the interface 0.0.0.0 causes them to receive all data. ... if I have a socket that joins the SAME ... > multicast group but is tied to a different interface it will not receive ...
    (comp.os.linux.networking)