problem with winsock.senddata 
Author Message
 problem with winsock.senddata

hi
i am trying to imitate a webbrowser
what am i doing wrong?

   Winsock.RemoteHost = "www.netscape.com"
    Winsock.RemotePort = 80
    Winsock.Connect

    Winsock.SendData "GET / HTTP/1.0" & vbCrLf & "Connection:
Keep-Alive" & vbCrLf & _
                        "User-Agent: bs" & vbCrLf & _
                        "Accept: image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, image/png, */*" & vbCrLf

i always get the error  40006. wrong protocol or connection state
how should i do it?

/konrad



Tue, 13 Aug 2002 03:00:00 GMT  
 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



Tue, 13 Aug 2002 03:00:00 GMT  
 problem with winsock.senddata
thanks, works fine now.
/konrad
Quote:

> 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



Tue, 13 Aug 2002 03:00:00 GMT  
 problem with winsock.senddata

Quote:

> hi
> i am trying to imitate a webbrowser
> what am i doing wrong?

>    Winsock.RemoteHost = "www.netscape.com"
>     Winsock.RemotePort = 80
>     Winsock.Connect

>     Winsock.SendData "GET / HTTP/1.0" & vbCrLf & "Connection:
> Keep-Alive" & vbCrLf & _
>                         "User-Agent: bs" & vbCrLf & _
>                         "Accept: image/gif, image/x-xbitmap, image/jpeg,
> image/pjpeg, image/png, */*" & vbCrLf

> i always get the error  40006. wrong protocol or connection state
> how should i do it?

> /konrad

Just a quick pointer,

Try using the Winsock API itself and not the Winsock control.  The
Winsock control takes more resources and is less flexible.  Also, the
winsock control is much slower than using the API's.

Another thing to think about is that the http protocol supports both UDP
and TCP streams on port 80 -- this can be found in the RFC's.  

So, If you want performance, flexibility, and reliability -- don't use
wrapped up code when you have access the API's themselves.  If you would
like, I can send you all the code you'll ever need to do winsock
programming.



Mon, 19 Aug 2002 03:00:00 GMT  
 problem with winsock.senddata
You should wait until you have a connection with the server before you start
sending the data! That's the only problem I can find..


Mon, 26 Aug 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. problem with WINSOCK.SENDDATA

2. winsock problem sending large strings (winsock.senddata)

3. winsock senddata problem/question

4. Winsock.SendData Problem

5. VB6: Winsock senddata problem - help!

6. Visual Basic Winsock senddata problem

7. WInsock SendData problem HELP

8. Winsock TCP SendData problem

9. Winsock SendData problems

10. Winsock SendData Problem?

11. Winsock SendData problem

12. senddata method problem in winsock control

 

 
Powered by phpBB® Forum Software