I wish an OpenNetworkConnection(ServerName$, Port,[LocalIp],[LocalPort],[Timeout]) having these three optional parameters
And it could be renamed OpenTCPConnection.
For reducing the timeout when you want to re-open a connection with the same ends, one needs to use setsockopt(...)
eg:
setsockopt (S, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (i));
setsockopt (S, SOL_SOCKET, SO_LINGER, &lng, sizeof (lng));
Then, for implementing LocalPort and LocalIp there is a need for calling bind(...)
before connect(...) eg:
bind (S, (struct sockaddr *) localend, sizeof (struct sockaddr));