locked
Usage of DataReader in StreamSocket client

    Question

  • I'm using DataReader to read data from server.

    My app is a DirectX App.

    I don't know when the server side will sent message to client.So I read in every frame.

    This failed with an exception:Access violation reading location 0x00000000.

    DataReader ^reader = ref new DataReader(mSocket->InputStream);

    create_task(reader->LoadAsync(sizeof(UINT32))).then([&, reader](unsigned int size) { if (size < sizeof(UINT32)) { cancel_current_task(); } return create_task(reader->LoadAsync(224)).then([&, reader](unsigned int actualStringLength) { if (actualStringLength != 224) { cancel_current_task(); } gd.GameID = reader->ReadInt16(); int charCount = 0; for (; charCount < 80; charCount++) gd.PlayerName[charCount] = (char) reader->ReadByte(); gd.PlayerName[charCount] = '\0'; gd.Date[0] = reader->ReadUInt16(); gd.Date[1] = reader->ReadUInt16(); gd.Date[2] = reader->ReadUInt16(); for (int i = 0; i < 4; i++) gd.Time[i] = reader->ReadUInt16(); for (int i = 0; i < 32; i++) gd.OtherData[i] = reader->ReadInt32(); wstring tempGDString = L"GameID:" + to_wstring(gd.GameID) + L"\nName:" + wstring(gd.PlayerName) + L"\nDate:" + to_wstring(gd.Date[0]) + to_wstring(gd.Date[1]) + to_wstring(gd.Date[2]) + L"\nTime:" + to_wstring(gd.Time[0]) + to_wstring(gd.Time[1]) + to_wstring(gd.Time[2]) + to_wstring(gd.Time[3]); }); });

    Any help will be appreciated.

    Thanks.

    Thursday, May 08, 2014 4:54 PM

All replies

  • Which line of code? What is the callstack?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, May 09, 2014 12:18 PM
    Moderator