friend said:
Hello all,
I am implementing a tool which can send and receive the data from the
remotehost...
while sending the data, if i send large amount of data at once my
application hangs..
and after everything has been send to remote system then my
application works...but mean while transferring the data the
application hangs...
how to resolve this issue ??
Please help me ....thanks to all
How you are sending? direct sockets, html request?
In general, in communications you have a basic principle
Send Low
Receive High
The theory is that you don't know what the receiver can handle, so you
send small chunks. But for receiving, you are in full control in
knowing what you can handle so you can afford reading large chunks.
It is basis for efficient and optimal data transfers.
If you are familiar with the IETF, the principle is best said with the
Jon Postel's axiom for robust protocol design:
Be conservative in what you send, liberal in what you receive.
The reason why your application main thread is more responsive with
smaller chunks is because the send data command has completed its
work, it is no longer blocked.
The large the chunk, the more time it needs to transfer the data which
will most likely include hardware flow control requirements, it will
block so your main thread is less responsive.
As others have suggested, using a background task or thread can help
alleviate the problem. But even the background task/thread should
take into account of sending smaller chunks.
Remember, if this a socket (internet) application, the socket is
limited to a fixed size, 4 to 8K is the general default size and to
best understand how to get an optimal transfer is to look at it as a
chain or Firemen Bucket Brigade.
WATER FIREMAN MAN CHILD FIRE
SOURCE --> BUCKET --> BUCKET --> BUCKET --> ... TARGET
You don't want anyone in the brigade to slow down the transfer of
water. You don't want half filled buckets (data size too small) and
you don't want to over fill because there is a max bucket size anyway.
Overfills, would be like each person having a overfill spill buckets:
SOURCE --> BUCKET --> BUCKET --> BUCKET --> ... TARGET
BUCKET BUCKET BUCKET BUCKET
That that will force a slow down because each person will have to stop
the previous person so he can finish passing all his buckets including
the spill buckets. This is the essence of data transfer sychronization
controls and in Windows parley "Overlapped I/O"
So you use a standard data transfer size so you can get a beautiful
synchronize flow of buckets in the brigade.
Note: A background thread/task is still recommended so that that your
main thread is not bogged down and can be more responsive.
Hope this provide some insight into why its happening.
--