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

WINSOCK LOCAL PORT

Status
Not open for further replies.

AdamWhitehouse

Programmer
Aug 7, 2000
34
0
0
GB
I am writing an applicatation that has multiple (4)winsocks on, in the form of an array, these are being used to control "intelligent cameras". When i try to connect using winsock(n).connect occasionally the connection will fail and time out, I reset the winsock with winsock(n) close, and after a for: doevents: next delay I try to reconnect, here's my problem the

localport has not been released ("Address in Use" error)

to get round this problem, after each connection failure I increment the localport and connect no problem, but I know this is bad codeing, why is it happening and how can I correct it?

 
What you need to do is have 5 winsock controls in your array. The first - winsock(0) - listens for new connections, and that is all that it does. When a new connection request arrives, in the Winsock_ConnectionRequest event sub procedure you create a new Winsock(n) control and have it accept the new request. The relevant code is below:

Dim intMax as integer 'global variable

Private Sub Form_Load()
intMax = 0
Winsock1(0).LocalPort = 2112
Winsock1(0).Listen
End Sub

'*******************************************************
'*******************************************************
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then 'should always equal 0, because Winsock1(0) is set to listen
intMax = intMax + 1 'advance control count by 1
Load Winsock1(intMax) 'load new winsock control
Winsock1(intMax).LocalPort = 2112 'set port of new winsock control
Winsock1(intMax).Accept requestID 'new winsock control accepts connection
End If
End Sub
 
Thanks for the reply, it doesn't help though, the 4 Winsocks I am using are Clients, with the Cameras by default(not optional) being Servers. I request a connection say 10.0.0.151, remote port 5001, local port 1. If the camera fails connection, Win98 / Vb does not release the local port. Because I do not know how to force closure of this port, (I AM closing the Winsock, if connection fails),I have two choices, open another local port or Reboot.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top