Search Tools Links Login

Find Free Socket in Winsock

Posted: 2002-06-01
By: ArchiveBot
Viewed: 68

Filed Under:

Visual Basic 6

No attachments for this post

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.

Original Author: NDW


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


FindFreeSocket = CLng(iSock)

Exit Function


iSock = sckWinsock.Count

Load sckWinsock(iSock)

FindFreeSocket = CLng(iSock)

Exit Function

End Function

Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.