Advertisement
7_2009-2012 Internet/ HTML #225917

Find Free Socket in Winsock

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.

AI

Résumé par IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Code source
original-source
<BR><BR><font face="verdana" size="1">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...<BR><BR>Create a winsock control and set index to 0. Example of code use:<BR><BR>
iSock = FindUserSocket(sckMyWinsock)<BR>
sckMyWinsock(iSock).Accept RequestID
<BR><BR>Function FindUserSocket(sckWinsock As Winsock) As Long<BR>
 Dim iSock As Integer<BR>
 For iSock = 1 To sckUser.Count - 1<BR>
 If sckWinsock(iSock).State = sckClosed Then<BR>
 GoTo SockFound<BR>
 End If<BR>
 Next iSock<BR>
 GoTo MakeSock<BR>
 Exit Function<BR>
SockFound:<BR>
 FindFreeSocket = CLng(iSock)<BR>
 Exit Function<BR>
MakeSock:<BR>
 iSock = sckWinsock.Count<BR>
 Load sckWinsock(iSock)<BR>
 FindFreeSocket = CLng(iSock)<BR>
 Exit Function<BR>
End Function<BR></font>
Commentaires originaux (3)
Récupéré via Wayback Machine