|
-
Jun 27th, 2009, 08:23 PM
#1
Thread Starter
Addicted Member
Maximum Connections
Instead of only having a certain amount of clients specified to connect to the winsock, how do I make it so it uses as much connections as possible? So it uses as many as the computer can hold instead of giving a specific amount?
-
Jun 27th, 2009, 10:07 PM
#2
Re: Maximum Connections
Like this.
It assumes that there's a Winsock control array on your form with the name "sckServer".
So, just add a Winsock control, name it "sckServer" and set its Index property to 0.
Code:
Option Explicit
Private Function Server_FindSocket() As Integer
Dim i As Integer, intRet As Integer
If sckServer.UBound = 0 Then
Load sckServer(1)
Server_FindSocket = 1
Else
For i = 1 To sckServer.UBound
If sckServer(i).State = sckClosed Then
intRet = i
Exit For
End If
Next i
If intRet > 0 Then
Server_FindSocket = intRet
Else
On Error Resume Next
'Could raise error if server is completely full
intRet = sckServer.UBound + 1
If Err.Number = 0 Then
Load sckServer(intRet)
Server_FindSocket = intRet
Else
Debug.Print "Connection rejected: server full!"
End If
On Error GoTo 0
End If
End If
End Function
Private Sub Form_Load()
sckServer(0).LocalPort = 1234
sckServer(0).Listen
End Sub
Private Sub sckServer_Close(Index As Integer)
sckServer(Index).Close
End Sub
Private Sub sckServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim intSocket As Integer
intSocket = Server_FindSocket
If intSocket > 0 Then
sckServer(intSocket).Accept requestID
Debug.Print "New connection on socket #" & intSocket & " from " & sckServer(intSocket).RemoteHostIP
End If
End Sub
I didn't test it, but it should work.
Last edited by DigiRev; Jun 27th, 2009 at 10:12 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|