views:

24

answers:

1

I'm updating legacy code written in VB6 using Winsock controls. Essentially, I'm trying to connect 4 computers across a local network such that the computers can share files between each other when needed. Originally, once a connection was established, they held onto them indefinitely. These would error after 12-24 hours, however, and couldn't be reestablished.

To make matters worse, the entire network is wrapped in tight security, and we only have a set number of ports to work with (their firewall blocks all other ports.) I suspect the network security is responsible for closing connections that have been inactive for too long, and are the cause of our instability (our tests here ran indefinitely and reestablished themselves if we rebooted any of the computers.)

My thought is to only establish connections on demand, when a file needs to be sent, to avoid this possibility. The problem I run into is that you cannot connect through the same port for four minutes. So no more than one file can be sent in a four minute window (unless you have all the files at once, but they're generated at different times.) Using three ports allow three files to be sent at once (one to each peer) but then I'm locked down for four more minutes. I could keep adding ports, but this seems inelegant at best, and will not be allowed by their IT department, at worst.

Any ideas? I can't find any other socket controls for VB6 that allow reusable bound ports.

A: 

The "four minute delay" is per connection, where a TCP connection is the 4-tuple consisting of the local IP, local port #, remote IP, and remote port #.

This is normally only an issue for a client that tries to establish a connection to a server using the same localport value repeatedly. For the Winsock control you might try simply setting LocalPort to 0 before attempting each new connection to the remote server.

Another way that might avoid connections sitting in TIME-WAIT is to be sure to actively CLOSE the connection when the CLOSE event is raised by the other end.

Using 3 ports to send 3 files seems a little odd. I wouldn't think this gains you any performance over sending the 3 files one after another using a single connection.

Bob Riemersma
I understand that this is per connection, but the problem is that we are working under a locked down firewall, and **can't** let `LocalPort` be 0 because then it will most likely pick a port that hasn't been opened. 3 ports are used to send 3 files to the 3 different peers - not different peers. I do actively close my local socket when I receive a close event from the remote socket.
Daniel Rasmussen
If the firewall was set to restrict source port (local port) numbers almost nothing would work. Normally the restriction is on destination port numbers. While it is possible a firewall might be set up to allow any source port for certain well known destination ports (HTTP, HTTPS, SMTP) and be restrictive about the source ports for anything else... this seems pretty unlikely. Your server needs to bind to and listen on a specific port but your client LocalPort values should be able to vary all over the ephemeral port range.
Bob Riemersma