
problem with winsock.senddata
First of all make sure the winsock control is using TCP. Second you have to
wait until the connection is made so put your SendData code behind the
Connect event. When your SendData code is ran the winsock control is in the
"connecting" state, it has to be in the "connected" state for SendData to
work which is why you get the message about the wrong state.
Private Sub Command1_Click()
Text1 = ""
Winsock1.Protocol = sckTCPProtocol
Winsock1.Connect "www.microsoft.com", 80
End Sub
Private Sub Winsock1_Connect()
Dim sText As String
sText = "GET /default.asp HTTP/1.0" & vbCrLf & "Accept: text/html" &
vbCrLf & vbCrLf
Winsock1.SendData sText
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sText As String
On Error Resume Next
Winsock1.GetData sText
Text1 = Text1 & sText
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String,
ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
HelpContext As Long, CancelDisplay As Boolean)
MsgBox Number & " - " & Description, vbCritical, App.Title
End Sub