PDA

Click to See Complete Forum and Search --> : sending data to multiple winsock connections


Apr 1st, 2000, 02:11 PM
Help! i am trying to send data to multiple users using the winsock control. the program i am creating is a chat program that has a server that clients connect to. the code i am currently using is below.

Dim i As Integer

For i = 1 To intMax
SendKeys "{ENTER}", False
MsgBox ""
sckServer(i).SendData data
Next

intMax is an integer that keeps track of the number of winsock controls.
when i dont use the sendkeys and msgbox, the data doesnt get sent back to the first client to connect to the server. when i put the sendkeys and msgbox in, it works fine. i cant understand why this is, any ideas would be appreciated! Thanks.

njaguar
Apr 7th, 2000, 06:27 AM
This is a bug in VB 5 and 6... It queues up data to any previously opened connection, instead of sending the data, like it should. :(

Check out msdn.microsoft.com for more information..

If anyone knows a way around this, PLEASE respond! I really am not looking forward to rewriting my server in the winsock API...

Thanks..

Fox
Apr 7th, 2000, 06:37 AM
I had also this problem, try the following...
Wait for the WinSock.SendComplete -event before you go on with the loop. Looks something like this:

'Declarations
Global Sent as Boolean

'In sckServer_SendComplete
Sent = True

'Your Loop
Dim A As Integer

For A = 1 To intMax
'Send data
sckServer(A).SendData data

'Wait for sent-event
Sent = False
While Sent = False
DoEvents
Wend
Next

Ok then, hope this helps ya...

njaguar
Apr 8th, 2000, 03:16 AM
That code only "waits" for the data to send. This works on one connection, but there is a bug with an array of connections that makes the previously connected connectiosn NOT get their data (it queues instead of sends it)... It will send the data, if it recieves some data from that client, so constantly pinging the server "works", but is obviously very inefficient.. All that code will do is wait indefinately until it can send it (which it won't be able to do because of that bug.. :(

Thanks anyway..

privoli
Apr 8th, 2000, 01:47 PM
Tested code...

Dim i As Integer

For i = 1 To intMax
SendKeys "{ENTER}", False
MsgBox ""
sckServer(i).SendData data
DoEvents 'Flush buffer/sockets and what not
Next

Fox
Apr 8th, 2000, 10:33 PM
I think it's a really stupid way to do this with a msgbox!

Erm, njaguar, did you try out my code?

privoli
Apr 8th, 2000, 11:49 PM
Dim i As Integer

For i = 1 To sckServer.UBound
if sckServer.State = SckConnected Then sckServer(i).SendData data
Next

Stoinker
Apr 9th, 2000, 07:56 AM
This problem only occurs with the Winsock control. My friend had a problem very much like this, and he simply switched to the Catalyst Socket Wrench control. It has a lot more features than Winsock (slightly more complex too.) You can download the control for free at http://www.catalyst.com/
Catalyst makes controls for just about every protocol, so make sure you get the right one (TCP/IP.) It is a great control and I have never once gone back to using the Winsock control since I have used Socket Wrench.

~Stoinker~