I don't use winsock. It's functionality is limited in the realm of sockets, and to make matters worse, I find the code you need to work with it... well, leaves a lot to be desired. I prefer the use of a control that is free from http://www.catalyst.com , known as socketwrench. It makes working with sockets 100 times easier, and it gives a whole list of properties and methods that make winsock look like a joke. Anyhow, I have written a port-scanner in VB6, and you can download the source from this thread:
http://www.daniweb.com/techtalkforums/thread18197.html
Let me know if this helps! If you really MUST use winsock, maybe the concept behind how my port scanner runs will help give you the same idea to use with your winsock app.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
looked at TTPScan and gets error loading cswsk32.ocx on loading into vb.
You don't need it.... it uses winsock because it's on everyone's computer, the other is there just for the ping sweeper, and it's not needed for the port scanner.
I'll be willing to bet, the error that you are recieving however, is because the socket is still connected. With winsock, you have to use .state (socketwrench has a .connected property) to test if the socket is connected before trying to reconnect. So, you do a loop with a doevents in the middle, and wait for the socket's state to become closed. Another thing to take into consideration, is maybe instead of a for loop, try using a variable that keeps track of which server you are scanning, and when the list of scanned ports completes, if it's the last port to scan for that IP, on the socket's error or connect event, call a socket close (disconnect), and start on the next IP.
The problem with the for loop, is that it doesn't wait. It loops each iteration until it's done, and the only way to get it to stop is to break out of it or use a sleep. The sleep will pause your entire app though, not just the loop. So, we need to look at working with event driven looping. On Error, On Connect, On Close, etc. The socket is a control array, so it's not that difficult to check if we are on a our final port by using the passed "index". Also, I don't know if it makes any difference, but you start your for loop at 1, and i'm wondering if the first IP is at 0?
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Ah! Very good catch. Let me know how the project turns out, or if the methods that I suggested above worked... It'll be fancy to hear what happens. Also, If you encounter any other problems with it, don't hesitate to ask.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215