|
-
Jan 4th, 2006, 08:49 AM
#1
Thread Starter
Member
[RESOLVED] Multiple connections
I have a multiple client-server setup using VB 6.0 that is connecting upto 30 computers at once across a LAN using TCP/IP connection. After all the client computers are connected to the server computer, I was trying to broadcast a command to all the clients at once, but as I itterated through each winsock connection, the command would only being recieved by last computer which connected. Is there any way to do this so all the computers that are connected the receive the command?
VB Code:
for idx = 1 to 30
Socket(idx).SendData CmndStrng
next
Last edited by dlern; Jan 26th, 2006 at 10:56 AM.
-
Jan 4th, 2006, 09:09 AM
#2
Re: Multiple connections
What type of connection do you use?
TCP or UDP?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jan 4th, 2006, 09:12 AM
#3
Thread Starter
Member
Re: Multiple connections
TCP and don't want to use the UDP broadcast method
-
Jan 4th, 2006, 09:15 AM
#4
Re: Multiple connections
You say that the 30 computers are all connected, did check them all? (I let each of them send a message when connected to server. That way Im sure all are connected)
The sending code by itself seems okay to me (whatever that says)
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jan 4th, 2006, 09:21 AM
#5
Thread Starter
Member
Re: Multiple connections
VB Code:
Private Sub Form_Load()
lblHostID.Caption = Socket(0).LocalHostName
lblAddress.Caption = Socket(0).LocalIP
Socket(0).LocalPort = 1007
sServerMsg = "Listening to port: " & Socket(0).LocalPort
List1.AddItem (sServerMsg)
Socket(0).Listen
End Sub
Private Sub socket_Close(Index As Integer)
sServerMsg = "Connection closed: " & "[" & Index & "]" & Socket(Index).RemoteHostIP
List1.AddItem (sServerMsg)
Socket(Index).Close
Unload Socket(Index)
iSockets = iSockets - 1
lblConnections.Caption = iSockets
End Sub
Private Sub socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
sServerMsg = "Connection request id " & "[" & sckCount & "]" & requestID & " from " & Socket(Index).RemoteHostIP
If Index = 0 Then
List1.AddItem (sServerMsg)
sRequestID = requestID
iSockets = iSockets + 1
sckCount = sckCount + 1
lblConnections.Caption = iSockets
Load Socket(sckCount)
Socket(sckCount).LocalPort = 1111
Socket(sckCount).Accept requestID
Debug.Print requestID
End If
End Sub
Private Sub socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
' get data from client
Socket(Index).GetData sRData, vbString
End Sub
Private Cmnd_click
for idx = 1 to 30
Socket(idx).SendData CmndStrng
next
End sub
-
Jan 4th, 2006, 09:24 AM
#6
Thread Starter
Member
Re: Multiple connections
I have include the server code. Within the form, the number of active connections is listed as a label and a listbox displays as each client connects or closes.
So I do know all of the clients are connected, but the command only gets received my the most recently connected client (client form also displays the received data).
Any ideas?
-
Jan 4th, 2006, 09:49 AM
#7
Re: Multiple connections
i've only browsed the thread but try this,
VB Code:
for i = 0 to winsock.ubound - 1
if winsock(i).state = sckconnected then
winsock(i).senddata Data
end if
doevents
next i
Pino
-
Jan 4th, 2006, 10:12 AM
#8
Re: Multiple connections
do all your connections share a single port on the serverside?
I think that is the problem!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jan 4th, 2006, 10:26 AM
#9
Re: Multiple connections
opus is correct your code here needs changing.
VB Code:
Private Sub socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
sServerMsg = "Connection request id " & "[" & sckCount & "]" & requestID & " from " & Socket(Index).RemoteHostIP
If Index = 0 Then
List1.AddItem (sServerMsg)
sRequestID = requestID
iSockets = iSockets + 1
sckCount = sckCount + 1
lblConnections.Caption = iSockets
Load Socket(sckCount)
Socket(sckCount).LocalPort = 1111
Socket(sckCount).Accept requestID
Debug.Print requestID
End If
chang eit to this....
VB Code:
Private Sub socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
sServerMsg = "Connection request id " & "[" & sckCount & "]" & requestID & " from " & Socket(Index).RemoteHostIP
Load Winsock(Winsock.UBound + 1)
Winsock(Winsock.UBound).Accept RequestID
End Sub
Not the 100% best way but for 30 sockets you should be ok, and it will work
-
Jan 4th, 2006, 02:57 PM
#10
Thread Starter
Member
Re: Multiple connections
Pino, that fixed it perfectly. I can now send commands to individual clients or broadcast to all the connected clients.
Only, what is the problem with this method. What if I was connected to 100 clients, or 500?
Thanks Again!!!!!!
-
Jan 4th, 2006, 04:44 PM
#11
Re: Multiple connections
the code i gaev u will let you have 1 million clients connect (memory dependant)
Basicly its not so good because lets say we have 5 clients connected and client 3 leaves and so does client 1, thast 2 open slots not being used just munching memory, good code would search each slot to see if its free, but for now you dont need to concern yourself with that!
Pino
-
Jan 9th, 2006, 11:43 PM
#12
Re: Multiple connections
Look at the server side project in here:
VB - How to send a file using the Winsock control
That is how you properly accept connections. The server is re-using sockets that are closed, therefore saving memory.
-
Jan 12th, 2006, 03:04 PM
#13
Hyperactive Member
Re: Multiple connections
....I'm just adding my two cents here....
Instead of sending individual messages to each computer (especially if you get into the hundreds of connections) what about using a multicast address. This is not difficult to do in Visual Studio and is extremely efficient for sending one copy of a message to many computers (thousands, if your network can support it) simultaneously. This also solves the issue of computers leaving the network during the broadcast because the multicast mechanisms automatically adjust when clients join/leave the multicast domain.
The only caveat here is that if your computers are on different subnets you will need to make sure your routers support multicast routing.
Last edited by MagellanTX; Jan 12th, 2006 at 03:08 PM.
-
Jan 12th, 2006, 03:13 PM
#14
Re: Multiple connections
He's using VB6, you can't do multicast in VB6...
-
Jan 12th, 2006, 03:23 PM
#15
Hyperactive Member
Re: Multiple connections
Whoops, was focusing on the issue as a whole...completely missed that important detail.
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
|