Visual basic winsock control

R

Thread Starter

Richard Friend

Need help on how to specify which network card the socket is to bind to using the MS winsock control under the TCP protocol, the .bind method works for UDP but using it for TCP causes error "invalid operation at current state" when calling the connect method?
 
A

Alejaga, Ruel

Richard,

We might be able to provide more accurate insight
if you could post the line of code giving you the problem, presumably with the WinsockControl.bind method.

This solution should be fairly straightforward if you can provide the missing information.

Regards,

Ruel

___________________________
Ruel V. Alejaga
[email protected]
Systems Engineer
Control Masters, Inc.

Web: http://www.controlmasters.com
5235 Katrine Ave. Voice: 630-968-2390 x309
Downers Grove, IL 60515 FAX: 630-968-3260
 
L
This is not an exact answer per your question, but I suspect this may be part of your trouble.

Make sure you use a unique "source TCP port" number each time you try to open a socket under Windows. Unless things have changed, Windows enforces some kind of time delay which prevents you from RE-OPENING a socket on a "just used" port number within some timeout period. So if you run your program, then stop it, make a quick change, then run it again the socket may fail to open since the "old" socket is still in the process of exiting.

Usually the "source" port is not important - for example to use Modbus/TCP you must use port 502 as the DESTINATION, but the remote node will happily reply with Modbus/TCP responses to any source port.

You may want to check out "socket wrench", which is a free OCX for VB which provides a simplified interface to WinSock http://www.catalyst.com/download/wrench.html

Regards

Lynn August Linse, Senior Product Application Engineer
15353 Barranca Parkway, Lantronix Inc, Irvine CA 92618
[email protected] www.lantronix.com
Tel: (949)450-7272 Fax: (949)453-7132
 
R
Lynn Linse wrote:

> Make sure you use a unique "source TCP port" number each time you try to
> open a socket under Windows. Unless things have changed, Windows enforces
> some kind of time delay which prevents you from RE-OPENING a socket on a
> "just used" port number within some timeout period. So if you run your
> program, then stop it, make a quick change, then run it again the socket may
> fail to open since the "old" socket is still in the process of exiting.

I think things have changed, last week I wrote a little VB program that, whenever an error is raised on the socke, simply closes it and reopens it. Works.
 
did you ever find a solution for this? i have found the same problem. you can use the bind method to assign the ip you want to use, it opens the winsock state, so you have to close it.. then you can go and connect out, while the local ip property shows the proper ip you jsut bound.. it actually uses the first ip in the network properties regardless. it only has this error with tcp though, with udp using the different ips works fine.
 
I'm also trying to find out how to point a winsock control to a certain card.

Two points about the previous notes though :

1. the bind statement is for UDP only. As it is a connectionless protocol, you have to bind it to the remote address and port, so that's why it doesnt work with tcpip.

2. Setting the localport to Zero will get windows to randomly select a free port to use to connect to a remote host. This way, you dont have to wait or worry about the tcpip port timeout

Null

 
R

Ruel V. Alejaga


We might be able to provide more accurate insight if you could post the line of code giving you the problem, presumably with the WinsockControl.bind method.

This solution should be fairly straightforward if you can provide the missing information.

Regards,

Ruel

___________________________
Ruel V. Alejaga
[email protected]
Systems Engineer
Control Masters, Inc.

Web: http://www.controlmasters.com
5235 Katrine Ave. Voice: 630-968-2390 x309
Downers Grove, IL 60515 FAX: 630-968-3260
 
Top