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.
精彩评论