locked
How to read networkstream with Visual C++ 2010 coming from WinRT client application.

    Question

  • Hi,

    I'm writing a server-client application which client is a WinRT (Metro) application running on my W8 PC and server is a desktop application running on my W7 PC.

    I figured out how to connect to a server and writing data to outgoing stream in WinRT, using StreamSocket sample, however I can not receive the content of this stream with the algorithm I coded with Visual C++ 2010 (modified version of MSDN Library sample), such as;
     
    Int32 port = 50000;
    String^ hostname = Dns::GetHostName();
    IPAddress^ localAddress = Dns::Resolve(hostname)->AddressList[0];
    TcpListener^ server = gcnew TcpListener(localAddress,port);
    array<Byte>^myBuffer= gcnew array<Byte>(256);
    server->Start();

    while (true)
    {
    TcpClient^ client = server->AcceptTcpClient();
    NetworkStream^ stream = client->GetStream();
    Int32 i;

    while ((i = stream->Read(myBuffer,0,myBuffer->Length))!= 0)
    {
    data = System::Text::Encoding::ASCII->GetString(myBuffer, 0, i);
    }
    client->Close();
    }

    When the client is a desktop application, I can easily recevie the data within the stream, however when the client is a WinRT (Metro) application, I can not.

    What kind of modifications I should make to my stream reading algorithm? Maybe I should read stream with Stream.ReadAsync method but this method did not work for Visual C++ (I have.NET Framework 4.5).


    • Edited by Noreturn85 Wednesday, September 05, 2012 2:56 PM Deleted unnecessary spaces.
    • Moved by Jesse Jiang Friday, September 07, 2012 6:06 AM (From:Visual C++ General)
    Wednesday, September 05, 2012 2:54 PM

Answers

All replies