PDA

Click to See Complete Forum and Search --> : winsock


johan1
Jan 10th, 2000, 02:27 AM
I got a problem...
check this code out:

Private Sub wTimer1_Timer()
If vänta.Enabled = True Then Exit Sub Else vänta.Enabled = True
If Winsock1.state = 7 Then Winsock1.SendData w1(1)
If Winsock2.state = 7 Then Winsock2.SendData w1(1)
If Winsock3.state = 7 Then Winsock3.SendData w1(1)
If Winsock4.state = 7 Then Winsock4.SendData w1(1)
If Winsock5.state = 7 Then Winsock5.SendData w1(1)
If Winsock6.state = 7 Then Winsock6.SendData w1(1)
If Winsock7.state = 7 Then Winsock7.SendData w1(1)
If Winsock8.state = 7 Then Winsock8.SendData w1(1)
If Winsock9.state = 7 Then Winsock9.SendData w1(1)
If Winsock10.state = 7 Then Winsock10.SendData w1(1)

wTimer1.Enabled = False
End Sub

And the only thing that happends is that winsock10 gets the data why?
If i delete "If Winsock10.state = 7 Then Winsock10.SendData w1(1)"
then winsock9 is the only datareciver..



[This message has been edited by johan1 (edited 01-10-2000).]

Jan 10th, 2000, 08:08 PM
why you don't use dynamicaly loaded winsock control ?


taLON

btw: what a programm you are writing ?

Jan 11th, 2000, 11:34 AM
http://support.microsoft.com/support/kb/articles/q245/1/59.asp

BUG: Winsock Control SendData Only Works Over the Latest Connection

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Professional and Enterprise Editions, 32-bit only, for Windows, versions 5.0, 6.0

--------------------------------------------------------------------------------


SYMPTOMS
For a 32-bit Visual Basic application with multiple Winsock Control objects that maintain TCP connections to other socket applications, SendData() only works over the most recently established connection. This behavior is reproducible on versions prior to and include Microsoft Visual Studio SP3.

CAUSE
The event messages associated with each SendData() are flushed from the message queue by the latest socket connection. This causes data to queue up and with no event messages available to start the data send process for previous connections.

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

Please contact Microsoft Technical Support if you need to know the current status of this bug.

For more information about eligibility for no-charge technical support, see the following article in the Microsoft Knowledge Base:

Q154871 Determining If You Are Eligible for No-Charge Technical Support

MORE INFORMATION
To reproduce the problem assuming an application maintains an array of three Winsock Control objects, each of controls has established a connection with its peer side over TCP. Label the connections as C1, C2, and C3 based on the order the connections are established, with C3 as the most recently established connection. If you attempt to do the following:

Private Sub cmdSendData_Click()
Dim i As Long<BR/><BR/>
For i = 1 To iIndex<BR/>
If (socks(i).State = sckConnected) Then
socks(i).SendData txtSendData.Text
End If
Next i
End Sub
Only the peer side of C3 connection get the messages. If you disconnect C3, the peer side of C2, which becomes the most recent connection at the time, will start to receive messages intended for it.

REFERENCES
For additional information, please see the following article(s) in the Microsoft Knowledge Base:


Q183987 PRB: SendData Method Generates Error 40006

Additional query words:

Keywords : kbnetwork kbCtrl kbSDKPlatform kbSDKWin32 kbVBp500 kbVBp600 kbWinsock kbDSupport kbGrpNet
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbbug



Last Reviewed: December 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.


------------------

Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl

johan1
Jan 12th, 2000, 02:06 AM
It isnt possible to fix it then?

ljdarten
Jan 26th, 2000, 06:15 PM
i actually ran into this a while ago, i did find a way around around it, but it's a pain in the ***.

if each connection is sent the data in a different procedure or function it works.
or if there is a small delay in between sends, im not sure what is the best answer, but this is the way i found out of it.

create a "buffer" to send the data to, instead of sending to all. simply a string, one for each user, if you want to track which tranfers were succesful (erase the string on sending, so if you go to set the string and anything's there, you know the last one didnt go)

then do one of two things,

create a timer that sends each connection individually (a timer array is kind of resource intensive, so i make a form level variable that it increments and uses to know which connection it's on.)

or, something i did a while ago that im not sure of the details, instead of creating strings, create a textbox for each connection(visible=false) that send the data on their text_change event. i did this one a while ago and to be honest i cant remember how well it worked.

either one you're using you can also turn the buffer into more of a true buffer, by adding to the end of it instead of resetting it. then when you send, take the first predetermined amount of characters (and cut then off too). that way no messages are lost if the connection experiences a slowdown.

you have to be careful with that though, i made a game that took data in faster than it was putting it out and got a string with 100,000+ characters in it.... a lil bit of a memory leak.



------------------
lucas darten
programmer-type guy

Bryan
Jan 26th, 2000, 10:03 PM
I created a chat app, and ran into this same problem. Why dont you try somthing like this. It should work just fine, it did for me.

You have to turn your Winsock into an array.


For i = Winsock.LBound To Winsock.UBound
If Winsock(i).State = sckConnected Then
Winsock(i).SendData MyData
DoEvents
End If
Next

Hope it all works out.
Bryan

PS. If you need, I can email you the chat app that I made as a example.

Jan 27th, 2000, 11:38 AM
You oculd also wait until the SendComplete event fires.

Makes it a bit slower but should work.

------------------

Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl

ljdarten
Jan 27th, 2000, 07:59 PM
i think we are all using different versions. i know in vb5.0 putting it in an array and sending in a for..next loop will not work. unless there are just different versions of the winsock dll floating around.. in which case i really need to update, the netgame im making is turning into a big pain in the butt with that bug.

sendcomplete event... that could work a lot better..

------------------
lucas darten
programmer-type guy

eegor
Mar 22nd, 2000, 03:57 AM
After sending anything through WINSOCK, it is very good to do the DoEvents method right after so the computer knows that it has finished and can go to the next line of code.

Winsock(1).SendData "WOW, IT NOW WORKS!"
DoEvents
Winsock(2).SendData "WOW, IT WORKS AGAIN!"
DoEvents

Also, do not use dynamic controls, use an array. If you want 10 WinSocks do this:

Make a WinSock control. Copy the control and when it asks to make an array, say yes. Do this 10 times and there you go! Then instead of doing that long pain in the @ss coding do a For...Next thing. Watch:

For i = 0 to 9
Winsock1(i).SendData "WOW, THIS IS A MESSAGE!"
DoEvents
Next i

MUCH EASIER!!!

- Jon