On Wed, Feb 24, 2010 at 12:36 AM, Valentin Schmidt <v...@dasdeck.com> wrote: >> And if you use an "if" instead of "while", >> then you lose even more incoming data. > > how come?
Ok, here your suggestion again: private function handleTcpData(event:Event):void { if(_socket.bytesAvailable) { // USE IF, NOT WHILE! try{ // CATCH THE EXCEPTION var str:String = _socket.readUTF(); updateGUI(str); }catch(e:Error){} } } The problem is that you read an UTF string with prefixed length just once. But since it's TCP sockets, data can arrive in different amounts. And in fact I see that sometimes not just one, but several UTF strings with prefix will arrive. But your if-code will process just the 1st one. And another problem with that code: if a half of a string arrives, then it will throw an EOFError, then go into the empty catch branch and just lose that data. Regards Alex _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders