0

I am trying to testing FTP by using SocketChannel, but it is not really in my expectation. I knew that I need to setup a selector algorithm which select the OP_CONNECT, OP_READ key to perform the connect and read function, everything is working fine but why the incoming data is not completely read? On the other hand, if I'm debugging the program, it can be read correctly as I doing it very slow. I thought it is synchronizing issue, so I try to submit only 1 key(even tried hard coded the method step by step, but the issue still existed.

Has anyone met this issue? How can I ensure that the full incoming data is ready to read instead of partial data only, sometimes no data (=.=")

taymedee
  • 484
  • 2
  • 5
  • 11
  • Using non-blocking IO and waiting for all the data to be available are mutually exclusive (because waiting for the full input requires blocking!). You need to choose one or the other. With non-blocking reads, you must make multiple successive reads until the end of data is reached. – Mark Peters Apr 28 '14 at 04:00
  • @MarkPeters what is "multiple successive reads", I did loop the read until -1, it might be the case that bytes are not available yet,but how could I ensure the end of data is reached?? loop for seconds even response -1? – taymedee Apr 28 '14 at 04:09
  • @taymedee Your protocol (say FTP) has to include a way to detect end of file. This could be a length sent earlier in the message, a special end of stream data sequence, control messages, etc. – Chris Pitman Apr 28 '14 at 04:22
  • I see, thanks Mark Peter and Chris Pitman :) – taymedee Apr 28 '14 at 04:26

0 Answers0