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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock UDP assign local IP address

Status
Not open for further replies.

TomSwingruber

Programmer
May 21, 2003
21
0
0
US
If I have 2 NIC cards how do I assign a UDP Winsock control
to a given local IP address?
 
To the best of my knowledge the only part of the bind
method allowed for UDP is >udpWinsock.Bind {PortNumber}<

I think that >udpWinsock.Bind {PortNumber}, "192.168.1.20"<
is only valid for TCP

But then I have been wrong before.
Thanks Tom
 
About the Bind Method

As shown in the code above, you must invoke the Bind method when creating a UDP application. The Bind method "reserves" a local port for use by the control. For example, when you bind the control to port number 1001, no other application can use that port to "listen" on. This may come in useful if you wish to prevent another application from using that port.

The Bind method also features an optional second argument. If there is more than one network adapter present on the machine, the LocalIP argument allows you to specify which adapter to use. If you omit the argument, the control uses the first network adapter listed in the Network control panel dialog box of the computer's Control Panel Settings.

When using the UDP protocol, you can freely switch the RemoteHost and RemotePort properties while remaining bound to the same LocalPort. However, with the TCP protocol, you must close the connection before changing the RemoteHost and RemotePort properties.
I don't see anything suggesting you can't use the second argument with UDP. However nothing specifically says you can either.
 
You were right the bind will work BUT there is
a strange quirk to it.
Probably not to you but sure is to me.

The winsock bind method will not allow the winsock.bind {Port}, {IP address} format
unless the NIC card is attached to an external device.
But will allow the winsock.bind {Port} method.

Plugging into a switch with no other devices connected to the switch allows binding to the IP address.
It will also bind if connected to a second computer with a null cable even if the second computer is set with completely different IP protocol.

Thanks for your help it inspired me to dig deeper.
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top