Announcement

Collapse
No announcement yet.

TCP RECV - GPF

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TCP RECV - GPF

    Howdy,

    I'm trying to use the TCP commands to read a web page but I'm getting a GPF every time I use the TCP RECV or TCP LINE commands. My code (PB/DLL 6):

    LOCAL sPageData AS STRING, sBuffer AS STRING

    sPageData = ""
    sBuffer = SPACE$(5000)

    ' Open the site
    TCP OPEN PORT 80 AT "www.nfl.com" AS #1

    ' Open the page
    TCP PRINT #1, "GET /gameday99/week13/scoreboard.html HTTP/1.1"
    TCP PRINT #1, ""

    ' Get the data
    DO
    TCP RECV #1, 5000, sBuffer

    sPageData = sPageData + sBuffer

    LOOP WHILE LEN(sBuffer)

    ' Close the port
    CLOSE #1

    This is my first PB app (longtime VB guy) so it's probably something dumb on my part, but I can't see where. The code above is only slightly modified from an example posted here not too long ago.

    Despite the above, I'm having a lot of fun with PB!

    Thanks,

    Mark
    Mark Newman

  • #2
    Try this: in the loop, prefill the dynamic string before each call to TCP RECV.
    ie,
    Code:
    DO
     sBuffer = SPACE$(5000)
     TCP RECV #1, 5000, sBuffer
     sPageData = sPageData + sBuffer
    LOOP WHILE LEN(sBuffer)


    -------------
    Lance
    PowerBASIC Support
    ( mailto:[email protected][email protected]</A> )
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance,

      Thanks for the reply. After a cold reboot the code is now working (well, at least it gets an error message reply from the server); maybe there was some conflict with one of the 533 DLLs that IE loads... ;^) (Now how do I get the smiley faces in here...?!)

      Mark
      Mark Newman

      Comment


      • #4
        Mark --
        Some advices.
        1) Use full address and HTTP/1.0:
        TCP PRINT #1, "GET http://www.nfl.com/gameday99/week13/scoreboard.html HTTP/1.0"

        HTTP 1.0, because not all proxy-servers understand HTTP 1.1

        2) Be careful with TCP OPEN
        TCP OPEN PORT 80 AT "www.nfl.com" AS #1 - is possible for Dial-Up only.
        For proxy it's necessary to use address and port of proxy-server (see IE settings on your computer)
        For example: TCP OPEN PORT 8080 AT "proxy" AS #1

        3) Note, that protocol HTTP/1.1 brings a title.
        I use following code
        kBuffer = 2048: Buffer$ = Space$(kBuffer): BytesRead& = 0
        Do
        Tcp Recv #1, kBuffer, Buffer$
        If Len(Buffer$) = 0 Then Exit Do
        If BytesRead& = 0 Then
        ij = Instr(Buffer$, Chr$(13, 10, 13, 10))
        If UCase$(Left$(Buffer$, 4)) = "HTTP" And (ij > 0) Then Buffer$ = Mid$(Buffer$, ij + 4) ' cut Title
        End If
        Print #2, Buffer$; ' I write contents to file #2 (ordinary OPEN .. For Output)
        BytesRead& = BytesRead& + Len(Buffer$)
        Loop


        [This message has been edited by Semen Matusovski (edited December 13, 1999).]

        Comment


        • #5
          Semen,

          Thanks for the tips! Using your information I can now download the web pages correctly.

          Mark
          Mark Newman

          Comment


          • #6
            Semen,

            As suggested if full address is used as follows:

            TCP PRINT # 1,"http://www.nfl.com/---etc HTTP/1.0"

            if works for all url's with www's however for url's that do not have www in the address such as following, it does not work.
            http://ibd.infostreet.com/cgi-bin/fr...source=ASD1JFD http://tradingclones.com/articles/article1-node1.htm http://perso.wanadoo.fr/pgreenfinch/ http://members.aol.com/ganntrader/ http://prodigy.snap.com/main/commodi...,25,-1,00.html http://cgi.ebay.com/aw-cgi/eBayISAPI...item=354192427

            In case of url's like above dropping http://xxxx.com seems to work.

            Anothr thing I have noticed is that if proxy server is used then full command does work. Without proxy server full command does not work.

            I will like to know a way to make full url work in tcp print command when there is no www in it.

            Thanks.

            Gajanan Raje


            ------------------
            Gajanan Raje

            Comment


            • #7
              I will like to know a way to make full url work in tcp print command when there is no www in it.
              The "www" is just part of some host names. It's no more or less important than those with or without the "www". You should use the normal syntax, replacing any "www" address you have with whatever the remote host name is, i.e.
              Code:
              TCP PRINT #1, "GET [url="http://somehost.somesite.com"]http://somehost.somesite.com[/url]  HTTP/1.0"
              The important part here is that the host is running an http server, not that it has "www" as part of its name. "www" is not required nor meaningful to http itself. It's just a common host name for web servers.


              ------------------
              Troy King
              [email protected]
              Troy King
              katravax at yahoo dot com

              Comment


              • #8
                Troy,

                Following code is for PBCC 2.0. I have included 2 urls one with www and one without. You can alternately comment out one and run the program. You will notice that you get an error message when you use full url without www in it. To check that the url is valid, you can paste the url in address field of the browser and you will be able to see the web page. I have not cleaned data received since this is only a test program.

                [CODE/]
                #DIM ALL
                #COMPILE EXE
                #DEBUG ERROR ON

                #INCLUDE "WIN32API.INC"

                FUNCTION PBMAIN() AS LONG

                LOCAL sPageData AS STRING
                LOCAL sBuffer AS STRING
                LOCAL Buf AS LONG
                LOCAL RecNo AS LONG
                LOCAL X AS LONG

                sPageData = ""
                sBuffer = SPACE$(4096)

                ' Open the site
                Buf&=FREEFILE

                TCP OPEN PORT 80 AT "www.nfl.com" AS Buf&

                ' TCP OPEN PORT 80 AT "tradingclones.com" AS Buf&

                IF ERR THEN
                PRINT "OPEN Error"; ERR
                WAITKEY$
                END IF

                ' Open the page
                TCP PRINT Buf&, "GET http://www.nfl.com/gameday99/week13/scoreboard.html HTTP/1.0"

                ' TCP PRINT Buf&, "GET http://tradingclones.com/articles/article1-node1.htm HTTP/1.0"
                TCP PRINT Buf&, ""

                ' Get the data
                DO
                sBuffer = SPACE$(4096)
                TCP RECV Buf&, 4096, sBuffer
                sPageData = sPageData + sBuffer
                LOOP WHILE LEN(sBuffer)

                ' Close the port
                CLOSE Buf&

                'print data for testing. data is not cleaned.
                RecNo&=PARSECOUNT(sPageData$,$LF)

                COLOR 15,0
                FOR X&=1 TO RecNo&
                IF X& MOD 20 THEN
                PRINT PARSE$(sPageData$,$LF,X&)
                ELSE
                LOCATE 25,1:COLOR 10,0
                PRINT "Press any key to continue"
                WHILE NOT INSTAT:WEND
                S$=INKEY$
                COLOR 15,0
                END IF
                NEXT

                WAITKEY$

                END FUNCTION

                [/CODE]

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


                [This message has been edited by Gajanan Raje (edited June 16, 2000).]
                Gajanan Raje

                Comment


                • #9
                  Originally posted by Gajanan Raje:
                  Troy,

                  Following code is for PBCC 2.0. I have included 2 urls one with www and one without. You can alternately comment out one and run the program. You will notice that you get an error message when you use full url without www in it.
                  It works great for me... For some reason I didn't paste the HTTP/1.0 after the second get, so I though that was the problem, but when I look at your code again, I see you had it there. Anyway, after I dimmed S$ to get rid of the compiler error, the code worked fine.
                  ------------------
                  Troy King
                  [email protected]

                  [This message has been edited by Troy King (edited June 16, 2000).]
                  Troy King
                  katravax at yahoo dot com

                  Comment


                  • #10
                    Sorry about that S$ . I have few different test files since I was working on this for last 3 or 4 days.

                    I have a program that does retrieve info. It was working fine until my ISP (prodigy) discontinued proxy server. When I open tcp port using proxy, full urls of all kind do work. The program I have posted above works if I drop "http://---.com" part from the url. I tried 3 different ISPs and all the urls in my previous post failed.

                    I am using IE5 browser. Which browser are you using ?

                    Thanks for taking time to check my sample code and response. May be I will have to switch to your ISP !!

                    Gajanan Raje

                    ------------------
                    Gajanan Raje

                    Comment


                    • #11
                      No problem. Folks here have helped me *many* times when I was having a problem. As to the browser (it shouldn't matter) I'm using IE5, Opera, Lynx, and Netscape 3, and on occassion, good ol' telnet. As to my ISP, I use RoadRunner cable through a local cable provider. It's decent for the money, I get about 600K/sec max download speeds.

                      Just in case there is some difference in the code we used, even though I pasted from your sample, I'm posting the exact code I compiled that successfully retrieved the page in question:

                      Code:
                      #DIM ALL
                      #COMPILE EXE
                      #DEBUG ERROR ON
                        
                      #INCLUDE "WIN32API.INC"
                        
                      FUNCTION PBMAIN() AS LONG
                        
                            LOCAL sPageData AS STRING
                            LOCAL sBuffer AS STRING
                            LOCAL Buf AS LONG
                            LOCAL RecNo AS LONG
                            LOCAL X AS LONG
                            DIM s AS STRING
                        
                            sPageData = ""
                            sBuffer = SPACE$(4096)
                        
                            ' Open the site
                            Buf&=FREEFILE
                        
                      '      TCP OPEN PORT 80 AT "www.nfl.com" AS Buf&
                        
                           TCP OPEN PORT 80 AT "tradingclones.com" AS Buf&
                        
                            IF ERR THEN
                              PRINT "OPEN Error"; ERR
                              WAITKEY$
                            END IF
                        
                            ' Open the page
                      '     TCP PRINT Buf&, "GET [url="http://www.nfl.com/gameday99/week13/scoreboard.html"]http://www.nfl.com/gameday99/week13/scoreboard.html[/url]   HTTP/1.0"
                        
                           TCP PRINT Buf&, "GET [url="http://tradingclones.com/articles/article1-node1.htm"]http://tradingclones.com/articles/article1-node1.htm[/url]  HTTP/1.0"
                            TCP PRINT Buf&, ""
                        
                            ' Get the data
                            DO
                              sBuffer = SPACE$(4096)
                              TCP RECV Buf&, 4096, sBuffer
                              sPageData = sPageData + sBuffer
                            LOOP WHILE LEN(sBuffer)
                        
                            ' Close the port
                            CLOSE Buf&
                        
                            'print data for testing. data is not cleaned.
                            RecNo&=PARSECOUNT(sPageData$,$LF)
                        
                            COLOR 15,0
                            FOR X&=1 TO RecNo&
                              IF X& MOD 20 THEN
                                PRINT PARSE$(sPageData$,$LF,X&)
                              ELSE
                                LOCATE 25,1:COLOR 10,0
                                PRINT "Press any key to continue"
                                WHILE NOT INSTAT:WEND
                                S$=INKEY$
                                COLOR 15,0
                              END IF
                            NEXT
                        
                            WAITKEY$
                        
                      END FUNCTION
                      ------------------
                      Troy King
                      [email protected]
                      Troy King
                      katravax at yahoo dot com

                      Comment


                      • #12
                        I get a "501: not supported" error with either address, and whether I use 1.0 or 1.1. I suspect I'm disallowed because of my domain. I'm using a dial-up and no proxies.

                        ------------------
                        Lance
                        PowerBASIC Support
                        mailto:[email protected][email protected]</A>
                        Lance
                        mailto:[email protected]

                        Comment


                        • #13
                          Lance,

                          When I pasted program from the forum, the url is shown with URL= and duplicate url

                          That is what gave error 501. After I cleaned that line it worked ok.


                          Troy,

                          After I pasted the code in a new file, to my surprise it worked. I believe what happened is that I was playing with following 7 urls:

                          'http://tradingclones.com/articles/article1-node1.htm

                          'http://ibd.infostreet.com/cgi-bin/freeoffer.cgi?source=ASD1JFD

                          'http://cgi.ebay.com/aw-cgi/eBayISAPI.dll?ViewItem&item=354192427

                          'http://members.aol.com/ganntrader/

                          'http://perso.wanadoo.fr/pgreenfinch/

                          'http://prodigy.snap.com/main/commodity/horoscope/0,25,-1,00.html

                          'http://charts-d.quote.com:443/960911671320?User=demo&Pswd=demo&DataType=DATA&Symbol=ES00M&Interval=5

                          While posting the code I forgot which ones worked and which one did not, and included the one that did work. Of the above 7 urls first 3 work ok when used as full urls in TCP PRINT.

                          Next 3 work if "http://-----.com" is removed in TCP PRINT statement.

                          The last url in the above list does not work with regular server but works through a proxy server. I will like to find a way to make that url work through a regular server.


                          Thanks.

                          Gajanan Raje

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


                          [This message has been edited by Gajanan Raje (edited June 18, 2000).]
                          Gajanan Raje

                          Comment

                          Working...
                          X