|
-
Dec 30th, 2002, 02:25 PM
#1
Thread Starter
Hyperactive Member
Multiple Winsocks
I have a question regarding multiple winsock connections between 1 server and several clients. Here is my setup:
I have 5 winsock controls on my form:
sckListen
sckRequest1
sckRequest2
sckAccept1
sckAccept2
In Form_Load I do
VB Code:
With sckListen
.Bind .LocalIP, 7777
.Listen
End With
So now I have sckListen listening on port 7777.
I then have 2 command buttons that I click in this order:
VB Code:
Private Sub Command2_Click()
sckRequest1.Connect sckListen.LocalIP, 7777
End Sub
' and then
Private Sub Command3_Click()
sckRequest2.Connect sckListen.LocalIP, 7777
End Sub
In my sckListen_ConnectionRequest I have this:
VB Code:
Private Sub sckListen_ConnectionRequest(ByVal requestID As Long)
If sckAccept1.State = sckClosed Then
sckAccept1.Accept requestID
Else
sckAccept2.Accept requestID
End If
End Sub
If I then check the states and ports of my winsock controls I see this:
Code:
Listen: Listening LocalPort:7777
Request1: Connected LocalPort:2783
Accept1: Connected RemotePort:2783
Request2: Connected LocalPort:2784
Accept2: Connected RemotePort:2784
Does this make sense? I want to be able to have one winsock
listening for any connection requests from clients, and it would
then create new winsock instances to accept those requests.
(I am familiar with loading and unloading new controls)
Is the above log correct? Are my Request and Accept winsocks now connected on those ports? So any data passed between them should not be lost or misplaced(even though my initial .Connect method was called with port 7777)?
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
-
Dec 30th, 2002, 02:30 PM
#2
Thread Starter
Hyperactive Member
I just changed my debug log to show this..
Code:
Listen: Listening LocalPort:7777
Request1: Connected LocalPort:2845 RemotePort:7777
Accept1: Connected LocalPort:7777 RemotePort:2845
Request2: Connected LocalPort:2846 RemotePort:7777
Accept2: Connected LocalPort:7777 RemotePort:2846
Does this make sense?...
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
-
Dec 30th, 2002, 02:31 PM
#3
you can accomplish this using a control array of winsock controls.. this is the most efficient way to do it because it allows your server app to load a new winsock control with each seperate incoming connection request from the client...
-
Dec 30th, 2002, 02:38 PM
#4
Thread Starter
Hyperactive Member
Yes, I had planned on using an array of winsocks. I have no concerns on that matter. What I was wondering about was the actual connections between these winsocks..the fact that it seems to be automatically assigning a new port for these incoming connection requests.
Basically I need to know if what appears to be happening actually is. If so then that will make my life easier. Will the "Accept" winsocks automatically connect on the next available port, and will there be no conflicts between all open connections, despite the fact that the initial port (7777) seems to be being used by them all..
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
-
Dec 30th, 2002, 04:33 PM
#5
Each instance of the winsock control has its own index even if they share the same port number. You'll probably have problems with 'address in use' errors since each remote IP can only be accessed with 1 winsock whatever its state if its remoteIP property already has a value. You can avoid that by unloading the instance after use or designating each instance to 1 remote IP address (no other instance can access same address). Side note, you wont be able to have three simultaneous winsocks to same remotehostIP.
-
Dec 30th, 2002, 08:21 PM
#6
Addicted Member
i think u want this code: (stole it from MSDN)..
Code:
Const MAX_CONNECTIONS =100
Private Sub Form_Load()
sckServer(0).LocalPort = 7777
sckServer(0).Listen
'load all winsock controls
For indx = 1 to MAX_CONNECTIONS
Load sckServer(indx)
Next indx
End Sub
Private Sub sckServer_ConnectionRequest _
(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
'find available winsock control
For indx = 1 to MAX_CONNECTIONS
If sckServer(indx).State <> sckConnected Then
'accept connection
sckServer(indx).Close
sckServer(indx).Accept requestID
Exit For
End If
Next indx
End If
End Sub
Get Quoted:
"If Shane Warne had given his mobile phone to Russell Crowe, neither of them would be in trouble."
"She has more troubles than a centipede with its legs crossed."
"For every action, there is an equal and opposite Government program."

-
Dec 30th, 2002, 10:02 PM
#7
brenaaro,
Search the forum for Winsock.
This question has been asked and answered several times.
-
Dec 31st, 2002, 10:00 AM
#8
Thread Starter
Hyperactive Member
Originally posted by TheSarlacc
i think u want this code: (stole it from MSDN)..
Code:
Const MAX_CONNECTIONS =100
Private Sub Form_Load()
sckServer(0).LocalPort = 7777
sckServer(0).Listen
'load all winsock controls
For indx = 1 to MAX_CONNECTIONS
Load sckServer(indx)
Next indx
End Sub
Private Sub sckServer_ConnectionRequest _
(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
'find available winsock control
For indx = 1 to MAX_CONNECTIONS
If sckServer(indx).State <> sckConnected Then
'accept connection
sckServer(indx).Close
sckServer(indx).Accept requestID
Exit For
End If
Next indx
End If
End Sub
Ok I do something like this except I dont load the other winsocks untill they are needed. This is what I wanted to know, as long as the same concept is in MSDN then I'm satisfied.
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
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
|