It seems according to our tests that if close a DataSocket the information that was “recently” written is not sent.
We are using FTP in AS3 code, and open a command and data socket.
The dataSocke is correctly flushed everytime that we write on it.
The thing is that we closed the socket when all the information from the fileStream has been read and written/flushed to the dataSocket.
In speudo-code:
-bytesToWrite = filestream.bytesToRead();
-Datasocket.write(bytesToWrite).
-Datasocket.flush():
-if (filestream.noMoreData)
DataSocket.close().
if we use a timer (about 10 seconds) to close the socket, it is correctly send, if is not, the file in the server is incomplete.
The curious thing is that, after the flush, closing a socket, is just closing a socket, the SO has this information to send and decides when to send it, you cand not say “hey transport layer, do not send what i just wrote you” :-).
But it seems that in fact as3 sockets are doing something like that.
I’ve read docs and if you make a flush, it should go to SO responsibility, so even after closing the AS3 socket, if the SO has a information to send, it should send it.
Any idea why this behavior is presented?
Thanks in advance.
Please read The ultimate SO_LINGER page, or: why is my tcp not reliable to understand what’s going on at the socket API and kernel stack level.
Then follow the advise and put at least some basic application-level protocol on top of raw TCP byte stream – tell the receiver the length of data it is about to receive, send acknowledgment that everything has been read back to the sender.