I would like to use DataReader in order read messages sent from a client. Here is my code :
private async void Listener_ConnectionReceived(StreamSocketListener sender,
StreamSocketListenerConnectionReceivedEventArgs args)
{
try
{
using (DataReader reader = new DataReader(args.Socket.InputStream))
{
string receivedData;
var count = await reader.LoadAsync((uint)reader.ReadInt32());
receivedData = reader.ReadString(count);
Debug.Log("Received : " + receivedData);
}
}
catch (Exception e)
{
Debug.Log("Error: " + e.Message);
}
}
However I receive this error message : The operation attempted to access data outside the valid range (Exception from HRESULT: 0x8000000B) Any idea ? thanks!
(uint)reader.ReadInt32()
This code is trying to read an integer at the start of the stream indicating the length of the rest of the data that is being sent through. In all likelihood, the sender is not populating that integer correctly. Ask them to set it.
User contributions licensed under CC BY-SA 3.0