开发者

Is Socket.flush() necessary after reading data?

开发者 https://www.devze.com 2023-01-30 04:50 出处:网络
I am having problems with a project which makes intensive use of sockets with Smartfox Server. Sometimes, with Chrome, sockets d开发者_运维技巧ata seems to contain previous data (message from SFS are

I am having problems with a project which makes intensive use of sockets with Smartfox Server. Sometimes, with Chrome, sockets d开发者_运维技巧ata seems to contain previous data (message from SFS are in double).

Anyway my question is pretty simple ; anytime you read data from a socket, are you supposed to call the flush() method after ? I know it's highly recommended to do so when you are sending data.

....
socket.addEventListener(ProgressEvent.SOCKET_DATA, handleSocketData);
....

private function handleSocketData(evt:Event):void
{
    var o:Object = socket.readObject();
    ....
    socket.flush(); // is that necessary???
}


No. It is to flush the output data.


No, you should read the response data with something like -

  while ( socket.bytesAvailable ) {
        var data:String = socket.readUTF();
        Alert.show(data);
  }


We use Sockets in Flash with SFS server too. and we never flush the socket after reading, we only flush it (and must do) after writing to its byte buffer.

0

精彩评论

暂无评论...
验证码 换一张
取 消