
senddata method problem in winsock control
You have to wait until the server on the other end has accepted the
connection. Do this by trapping the Connect event.
Try this code. You'll need a form with a multi-line text box, a winsock
control and a command button. Pushing the button connects to port 80 of a
web server then (when the connection is established) it sends the correct
data to get a web page then displays the reults in the text box
Option Explicit
Private Sub Command1_Click()
Text1 = ""
Winsock1.Protocol = sckTCPProtocol
Winsock1.Connect "www.ntl.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