locked
Multicast message between Win32 and WinRT

    Question

  • Hello, I'm trying to connect two applications via Multicasting.

    One app is a Win32 app (using win32 sockets API). This app has been running for some years though I think its code is tested and solid. And I can connect two instances between them without any problem.

    The problem comes when I try to connecting the Win32 app with a Metro app (using the Metro API).

    The Metro app is able to connect to the network and send packages, but only himself receive them. The Win32 app seems like it's not receiving anything. I also tried to connect the Win32 app to the Metro app, but again nothing happen.

    I can not launch two instances of the Metro App, so I cannot test if they can see each other.

    Is there any limitation with the DatagramSocket API?

    Here is the Metro code for connecting to the network:

    DatagramSocket^ listener = ref new DatagramSocket();
    SocketContext^ listenerContext = ref new SocketContext(listener);
    listener->MessageReceived += ref new TypedEventHandler<DatagramSocket^, DatagramSocketMessageReceivedEventArgs^>(listenerContext, &SocketContext::OnMessage);
    
    // Start listen operation.
    listener->BindServiceNameAsync(L"55555");
    
    // Try getting an exception.
    MyHostName = ref new HostName(L"224.0.1.186");
    listener->JoinMulticastGroup(MyHostName);
           

    Here is the Metro code for sending messages:

    IBuffer^ buffer = Windows::Security::Cryptography::CryptographicBuffer::CreateFromByteArray(arrByte);
    
    task<IOutputStream^>(listener->GetOutputStreamAsync( MyHostName, "55555")).then([buffer] ( IOutputStream^ stream )
    {
        try
        {
            create_task(stream->WriteAsync(buffer)).then([stream] (unsigned int bytesStored)
            {
                // For the in-memory stream implementation we are using, the FlushAsync() call 
                // is superfluous, but other types of streams may require it.
                return stream->FlushAsync();
          });
        }
        catch (Exception^ ex)
        {
            String^ error= ex->Message;
        }
    });

    Thank you!



    • Edited by Hugetto Friday, August 31, 2012 11:38 AM
    Friday, August 31, 2012 11:37 AM

Answers