VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Find Free Socket in Winsock

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.

Rate Find Free Socket in Winsock



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

Download this snippet    Add to My Saved Code

Find Free Socket in Winsock Comments

No comments have been posted about Find Free Socket in Winsock. Why not be the first to post a comment about Find Free Socket in Winsock.

Post your comment

Subject:
Message:
0/1000 characters