by NDW (1 Submission)
Category: Internet/HTML
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating:
(5 Votes)
Take a winsock control that is an array and use this function to find an availible sock/create a new one. Just thought I would submit something of mine to the site.
If you would like to create a server or other such program, you can initiate many connections over the same port by using this type of function. By creating an index of your Winsock you can create multiple connections over the same port...
Create a winsock control and set index to 0. Example of code use:
iSock = FindUserSocket(sckMyWinsock)
sckMyWinsock(iSock).Accept RequestID
Function FindUserSocket(sckWinsock As Winsock) As Long
Dim iSock As Integer
For iSock = 1 To sckUser.Count - 1
If sckWinsock(iSock).State = sckClosed Then
GoTo SockFound
End If
Next iSock
GoTo MakeSock
Exit Function
SockFound:
FindFreeSocket = CLng(iSock)
Exit Function
MakeSock:
iSock = sckWinsock.Count
Load sckWinsock(iSock)
FindFreeSocket = CLng(iSock)
Exit Function
End Function