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
224 stars 72 forks source link

TCPClient stay alive , send message and receive #117

Closed SmartAv closed 7 years ago

SmartAv commented 7 years ago

Hello , i'm trying to do smart Home application which will connect to TCP Server

i was using socket on Unity but i decided to move to xamarin i tried your plugin it's great , just when i connect to server and send message , i want to stay connected and send the message

not after i disconnect the message be sent , because i need to keep the client connected to the server for the server sending update sometimes to the client

how it can be done ?

SmartAv commented 7 years ago

ok i got it , it's my fault since i don't understand too much i forgot to use StreamWriter _streamWriter;

then i do that afte rconnect _streamWriter = new StreamWriter(client.GetStream());

        _streamWriter.WriteLine("text");
        _streamWriter.Flush();

thank you , this answer for anybody had the same miss understanding like me

rdavisau commented 7 years ago

Yes - the socket was likely being flushed on disconnect - you could call Flush yourself (as you have done) or specify a 0 buffer size if you're happy with the implications of that 👍