locked
MessageWebSocket in Windows Runtime COmponent

    Question

  • HI,

    I have a messagewebsocket to receive http packets inside Wndows Runtime Component. It is working fine for a XAML App. But in Component, ConnectAsync itself is not called while debugging. I am sending Dynamic reference from the XAML App that is comsuming this Component.

    Uri^ server;
    server=ref new Uri("ws://localhost:8080/ws/");
    MessageWebSocket^ ws = messageWebSocket;
    ws = ref new MessageWebSocket();
    ws->Control->MessageType =SocketMessageType::Utf8;
    ws->MessageReceived += ref new TypedEventHandler<MessageWebSocket^, MessageWebSocketMessageReceivedEventArgs^>(this, &Class1::MessageReceived);
    ws->Closed += ref new TypedEventHandler<IWebSocket^, WebSocketClosedEventArgs^>(this, &Class1::Closed);
    task<void>(ws->ConnectAsync(server)).then([this, ws] (task<void> previousTask)
    {
    try
    {
    previousTask.get();
    messageWebSocket = ws;
    messageWriter = ref new DataWriter(ws->OutputStream);
    }
    catch (Exception^ exception)
    {
    HandleException(exception);
    }
    });

    • Edited by AnjuR Wednesday, November 13, 2013 11:10 AM
    Wednesday, November 13, 2013 11:04 AM

All replies

  • Can you elaborate on what you mean by ConnectAsync is not called while debugging? Do you mean to say that the ConnectAsync function is present in the code, but that code is just bypassed and there is no connection actually made? Are you seeing an exception or some weird behavior?

    Can you post a sample to SkyDrive demonstrating your problem?


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Thursday, November 14, 2013 1:04 AM
    Moderator
  • ConnectAsync function is present in the code, but that code is just bypassed and there is no connection actually made.

    There is no exception also. 

    Uploaded the samples in skydrive: 

    https://skydrive.live.com/?v=FirstRunView#cid=EA4E6490013965F3&id=EA4E6490013965F3%21181

    Server.zip is an C# http websocket server.

    In Code.zip, Project Add is an winrt App which loads WinRTComcpp dll's.

    WinRTComcpp is an WinRTComponent which is the client for the websocket. I am passing the Dispatch handle from Add App.  Hope it is clear enough.

    Thursday, November 14, 2013 6:16 AM
  • Actually, Connection is made and the server is sending the data but it is not getting received in the client.  MessageReceived is not called. 

    What should be the Dispatcher Object in case of Component which does not UI?

    Dispatcher from GetForCurrentThread or dispatcher object passed from the calling App?

    Uploaded the code in the same skydrive location.

    Many thanks!!

    Thursday, November 14, 2013 12:02 PM
  • I have a WinRT Com as MessageWebSocket Client.

    Connection is made to the server and the server is sending the data but it is not getting received in the client.  MessageReceived is not called. 

    What should be the Dispatcher Object in case of Component which does not have UI?

    Dispatcher from GetForCurrentThread or dispatcher object passed from the calling App?

    Uploaded the code in the skydrive location: https://skydrive.live.com/?v=FirstRunView#cid=EA4E6490013965F3&id=EA4E6490013965F3%21181

    Many thanks!!

    Friday, November 15, 2013 7:19 AM
  • Why do you want to use the Dispatcher from the Runtime component? Maybe a better approach is to expose an event in your Runtime Component and then register for the event completion in your app. Then when the event completes, you could just raise the completed event and then the XAML page that has registered for the event will update the UI. See this for more information: http://msdn.microsoft.com/en-us/windows/apps/hh755799.aspx

    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Saturday, November 16, 2013 12:14 AM
    Moderator
  • I want to isolate the socket code in the dll. I will load the dll and then on dll will take the action. Other than loading the dll, I don't want any other code in the app. 

    why MessageReceived is not called at all? 

    Thursday, November 21, 2013 10:03 AM