Samik R. said:
Thanks a lot for the reply. I have some comments though (inline).
I apologize in advance for my lack of patience. I've been having a tough
week or so, and I'm not known for my great patience in the first place. So,
keep in mind that if you continue to insist on refusing to believe what you
are told, I won't have the patience to keep trying to help you.
That said, my comments to your comments...
Even though the connections are uniquely identified by both endpoints, it
might still be the problem.
It is NOT a problem. I already told you that it is NOT a problem. TCP is
quite commonly used by a wide variety of servers that always use the same
local endpoint, as derived from the listening socket, with connections
uniquely determined by the local/remote endpoint combination.
Since two or more sockets would share the same local endpoint, if they all
try to send data at the same time, it is like 2 or more people trying to
enter through a single window at the same time.
It is not like that at all.
I am pretty sure about this, because when I introduced a random delay
before sending over the file, the file went through without hanging.
Then your bug (and you do have a bug) has something to do with transmissions
attempting to occur at the same time. That doesn't mean that there is any
problem with multiple connections having the same local endpoint.
You can be "pretty sure" all you like, it doesn't change the fact that TCP
works just fine with a single listening socket, multiple connections
accepted from that listening socket all with the same local endpoint. If
you have problems, it's due to some other reason.
I actually did some research after posting: basically read the RFC
(
http://www.faqs.org/rfcs/rfc959.html). Actually, they have a different
design for this problem. The server has two components: (1) A protocol
interpreter (PI), which reads a line and replies accordingly, always
waiting for new connections at the same port, and (2) Data Transfer
Process, which exclusively takes care of file transfers. This transfer
happens at different port than the one where PI listens, which is
specified by the server at runtime.
The reason for FTP using multiple connections for its design has NOTHING to
do with any issues related to identical local endpoints. An FTP server can
host multiple clients on the same port (whether that is the interpreter or
transfer port) without any trouble at all, and this happens quite commonly.
So my solution would be either of (1) making the connecting to be
processed serially (and I can afford that since my file transfers are
pretty quick), or (2) follow the design of the ftp server.
Solution #1 is fine if you don't mind that you have a bug in your code. It
probably will successfully avoid the bug, but you won't have fixed the bug,
and it's possible the bug is more serious than just preventing simultaneous
access.
Solution #2 is just silly. Since the reason that FTP uses multiple
connections has nothing to do with the question of simultaneous transfers,
if following FTP's design causes your problem to go away then all you've
done is hide the bug (just as you might with Solution #1). More likely,
following FTP's design won't have any effect on your bug at all.
It's not clear to me why you refuse to believe me when I tell you that the
"same local endpoint" issue is a complete non-issue. But as long as you
persist in your dedication to that red herring, you are not going to fix
your real problem. You might hide it for a while, but as with all bugs, the
underlying actual bug is sure to show up in some form again later, if you
fail to fix it.
Good luck with that.
Pete