Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you use multiple network ports in vb6?

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
I recently installed one of my old programs on a clients new computer and noticed it had 4 network ports.
Luckily only one is in use.
I wondered how do you distinguish which port is which in an application?
In Windows 7 you can easily see and set different ip addresses in the ports but there seems no property of winsock to send different signals to different ports.
 
If you are talking about outbound TCP connections and sending UDP datagrams, then you don't specify which adapter to use.

The OS uses routing rules such as checking whether one adapter is on the same subnet as the target address, whether a static route has been configured to the target address' network, and if those fail the default gateways for each adapter are tried in turn using routing protocols.
 
Say I have 4 separate networks, 4 winsocks, one each to use to receive data. 2 are clients, the other 2 are servers.
I presume the servers will automatically connect with the remote clients on the listening address specified in the server winsocks.
When I issue the Winsock.connect (to various different IPs in turn) to a client winsock, to connect to a remote server, will it automatically connect using the first winsock that finds the remote server? How will I know which Winsock Dataarrival Sub to use as these could be continually swapping?
 
> How will I know which Winsock Dataarrival Sub to use as these could be continually swapping?

Winsock operates at the session layer interface to the transport layer within the OSI 7 layer model (layers 4 and 5). It has no visibility of (nor does it care about) the network card in use (which resides at the physical layer, layer 1). A Winsock session will remain valid until it is torn down no matter which of multiple network cards (or routes over the LAN/WAN./Internet) the traffic flows.
 
Thanks, that cleared that up but unfortunately does not appear to be the result I had hoped.
I have started a new thread on a related but different question.
 
For a TCP server you normally select one adapter to listen on when you call the Bind method. If you omit this it will only listen on the "first" adapter, where "first" isn't easy to predict, but is most likely the first one in the linked list returned by a GetAdaptersInfo() call.
 
Thanks
I presumed the only use you would make of more than 1 adapter is if you wanted to connected to more than one entirely different networks eg local and exclusive internet modem.
Is there any advantage in having them both on the same network router? Eg speed?
 
There can be several reasons.

A really important one for servers supporting large numbers of clients is pretty simple:

IP port numbers (both TCP and UDP) are limited to 65536 unique values. Quite a few are reserved ports in each of the two protocols, and the ephemeral port range can be pretty narrow (normally well under 32K values). So to support large numbers of clients or peers you need multiple IP addresses.

Of course Windows Server and other server OSs support multiple IP "virtual adapters" (IP addresses) on each physical adapter. That helps get around the port number limits as well.

Then you get into performance. Physical adapters have finite onboard buffer memory and processing power, which can limit their effective bandwith when handling large numbers of conversations. The raw network may have capacity but the adapter is too busy to use it all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top