rdavisau / sockets-for-pcl

Cross-platform socket API for Xamarin iOS/Android/Forms, Xamarin.Mac/MonoMac, Windows Phone 8/8.1, Windows Store and Windows Desktop.
MIT License
223 stars 72 forks source link

Read Byte on ConnectionReceive Problems #111

Open Saccomani opened 8 years ago

Saccomani commented 8 years ago

I try use this code, but i am not able to get a byte array and convert to string...

the program stop when arrive the last byte..

can any one help me?

listener.ConnectionReceived += async (sender, args) => { var client = args.SocketClient;

var bytesRead = -1;
var buf = new byte[1];

while (bytesRead != 0)
{
    bytesRead = await args.SocketClient.ReadStream.ReadAsync(buf, 0, 1);
    if (bytesRead > 0)
        Debug.Write(buf[0]);
}

};

Digheads commented 8 years ago

I also got this bug. Something wrong with the reader, especially because the the whole network pipe is used as traditional stream object and not as a network stream. I had tested it out and it looks like the native stream object cannot serialize the incoming tcp packets as it should, its true especially when working with threads. There is something with the latency when reading, but im not remember what. Try using binaryreader. It worked for me as it supposed to.

ernestoyaquello commented 7 years ago

Any solution so far? I have tried using BinaryReader but it doesn't work either.