PDA

Click to See Complete Forum and Search --> : More fun with Winsock


Dec 22nd, 2000, 08:24 AM
Ok, I want to, IMMEDIATELY after winsock connects to the server (yes, this is TCP), then it'll send a list that you probably saw in the General VB forum:

Winsock1.Connect
Sleep 300 (or 5000; I'm contemplating both)
Dim iFile As Integer
For iFile = 0 To File1.ListCount - 1
Winsock1.SendData File1.List(iFile)
Next iFile

But it brings back

"Wrong protocol or connection state for the requested transaction or request"

Any ideas?

Sincerely,

Jedi Drunken Llama

Cander
Dec 22nd, 2000, 08:32 AM
Its sending before the the winsocks has fully connected. Add this after the line winsock1.connect:

Do until Winsock1.State = 7
DoEvents
Loop


Give it a shot

Dec 22nd, 2000, 08:40 AM
I'm going to test that in a few seconds, as soon as a friend replies via ICQ. Now, do I put

Dim iFile As Integer

For iFile = 0 To File1.ListCount - 1
Winsock1.SendData File1.List(iFile)
Next iFile

where you have "DoEvents"? I'm sorry, I'm very new at this. Hopefully, I can someday stop asking the questions and start answering them.

Sincerely,

Jedi Drunken Llama

ccoder
Dec 22nd, 2000, 08:54 AM
No, the Do Loop is there to force your code to wait until the connection has completed

Put the Do Loop before your For Next loop.

Dec 22nd, 2000, 09:18 AM
The above worked, and thanks for it! Now there's a new problem, and I don't know if this goes into General VB or into this forum; since I started it here, I'll post it here.

Now then, I have a list box set up so that the information that was sent in the discussion earlier will be reported there. Here's what I have:

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData
List1.AddItem strData & vbCrLf
End Sub

Unfortunately, it lumps all of the results into two lines (for both the client and server). Any idea?

Sincerely,

Jedi Drunken Llama

ccoder
Dec 22nd, 2000, 03:52 PM
See my reply to pir8eer's post: Sending and receiving in winsock gets mixed up! (http://forums.vb-world.net/showthread.php?threadid=45719). It may shed some light on your problem.