Announcement

Collapse
No announcement yet.

TIMEOUT in PBDLL6.0

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

  • TIMEOUT in PBDLL6.0

    Am I missing something here,
    the line:
    Code:
    TCP OPEN "smtp" AT MailServer$ AS hTCP& timeout 5
    does not work, the word 'timeout' does not turn blue and it does not return an error

    What am I missing ?

    tia
    Ian

  • #2
    The TIMEOUT keyword was left out of the syntax highlighting of the editor.

    Can you give an example of "not giving an error"?

    --Dave


    ------------------
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Home of the BASIC Gurus
    www.basicguru.com

    Comment


    • #3
      Timeout works - sure.
      I have a living program and when users type wrong address of proxy, a program can't link with server and works timeout.

      But Ian - timeout is interval is ms, not in seconds.
      You need 5000 (better more)

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

      Comment


      • #4
        Ok, i think you're right and my problem lies elsewhere.

        The problem is if I run a program that connects to a mail server, when I have a network connection all is fine but if I remove my network cable and try again it just hangs indeffinately.

        Any way out of this one ?

        Here's a small compileable demo:
        Code:
        'TCP Test
        
        $COMPILE EXE
        
        DECLARE CALLBACK FUNCTION GoForIt
        DECLARE FUNCTION goSMTP$(MailServer$)
        
        GLOBAL D1& 
        
        FUNCTION PBMAIN()
          CALL DialogOne
          
        END FUNCTION
        
        CALLBACK FUNCTION GoForIt
         CONTROL GET TEXT D1&, 20 TO a$
         MSGBOX a$,,""
         b$ = goSMTP$(a$)
         MSGBOX b$,,""
        END FUNCTION
        
        FUNCTION goSMTP$(MailServer$)
        DIM hTCP&, ip&, hostname$, buffer$, EmailError$
          HOST ADDR TO ip&
          HOST NAME ip& TO hostname$
        ' ** Connect to the mailhost
          hTCP& = FREEFILE
          TCP OPEN "smtp" AT MailServer$ AS hTCP& timeout 30 'gEmailServer$ is set from the main program (programstart [img]http://www.powerbasic.com/support/forums/smile.gif[/img]
          IF ERR THEN
             FUNCTION = "Error: Connecting to the Mailhost: " & MailServer$ & " " & STR$(ERR)
             EXIT FUNCTION
          ELSE
             FUNCTION = "Ok, connected fine."
          END IF
          TCP CLOSE hTCP&
        END FUNCTION
        
        SUB DialogOne
        #REGISTER NONE
          DIALOG NEW 0, "TCP Test", , , 186, 84, &Hc80800&, 0 TO D1&
          CONTROL ADD LABEL,    D1&,  10, "attempt to connect to:"   ,    55,   9,  75,   8, 0
          CONTROL ADD TEXTBOX,  D1&,  20, ""                  ,     43,  23,  99,  11, 0
          CONTROL ADD BUTTON,   D1&,  30, "Go For It"   ,     68,  47,  50,  14, 0 CALL GoForIt
          CONTROL ADD LABEL,    D1&,  40, "Now remove your network cable and try again"   ,    16,  69, 154,  10, 0
          ' ** Display the dialog
          DIALOG SHOW MODAL D1&
        
        END SUB
        Thanks

        Ian

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

        Comment


        • #5
          My guess is that it "hangs indefinitely" at the HOST statement which doesn't provide a mechanism for TIMEOUT.

          Do the HOST stuff after you successfully connect to the mail server. That way the TIMEOUT value in TCP OPEN will work.

          --Dave


          ------------------
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Home of the BASIC Gurus
          www.basicguru.com

          Comment


          • #6
            Nope, that didn't work.
            I tried remming out the hosts part altogether:
            Code:
            'TCP Test
            
            $COMPILE EXE
            
            DECLARE CALLBACK FUNCTION GoForIt
            DECLARE FUNCTION goSMTP$(MailServer$)
            
            GLOBAL D1&
            
            FUNCTION PBMAIN()
              CALL DialogOne
            
            END FUNCTION
            
            CALLBACK FUNCTION GoForIt
             CONTROL GET TEXT D1&, 20 TO a$
             MSGBOX a$,,""
             b$ = goSMTP$(a$)
             MSGBOX b$,,""
            END FUNCTION
            
            FUNCTION goSMTP$(MailServer$)
            DIM hTCP&, ip&, hostname$, buffer$, EmailError$
            ' ** Connect to the mailhost
              hTCP& = FREEFILE
              TCP OPEN "smtp" AT MailServer$ AS hTCP& timeout 30 'gEmailServer$ is set from the main program (programstart [img]http://www.powerbasic.com/support/forums/smile.gif[/img]
              IF ERR THEN
                 FUNCTION = "Error: Connecting to the Mailhost: " & MailServer$ & " " & STR$(ERR)
                 EXIT FUNCTION
              ELSE
                 FUNCTION = "Ok, connected fine."
              END IF
              TCP CLOSE hTCP&
            
            '  HOST ADDR TO ip&
            '  HOST NAME ip& TO hostname$
            
            END FUNCTION
            
            SUB DialogOne
            #REGISTER NONE
              DIALOG NEW 0, "TCP Test", , , 186, 84, &Hc80800&, 0 TO D1&
              CONTROL ADD LABEL,    D1&,  10, "attempt to connect to:"   ,    55,   9,  75,   8, 0
              CONTROL ADD TEXTBOX,  D1&,  20, ""                  ,     43,  23,  99,  11, 0
              CONTROL ADD BUTTON,   D1&,  30, "Go For It"   ,     68,  47,  50,  14, 0 CALL GoForIt
              CONTROL ADD LABEL,    D1&,  40, "Now remove your network cable and try again"   ,    16,  69, 154,  10, 0
              ' ** Display the dialog
              DIALOG SHOW MODAL D1&
            
            END SUB
            But it still hangs when you take the network cable out.
            It works again as soon as you plug the network cable in but....

            Ian


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

            Comment


            • #7
              Ian --
              What happends with browser (IE), if to turn off network cable ?

              I have dial-up connection. If to turn off modem or disconnect from Internet by another way (under Win2000) I simply receive Err = 57.
              (PS. Timeout 30 means 30 ms, not 30 seconds; but in any case it's not a reason of your problem)

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

              Comment


              • #8
                Semen,

                The problem I have is that I would like to detect when a user is not connected to the Internet and have the program display a message accordingly.

                If you compile my program (above) and attempt to activate it when you are NOT connected to the Internet then it will hang
                (at least it does for me).
                At this point I would like to suggest to the user that perhaps they are not connected to the Internet but I can't get past the hang part.

                Any help gratefully received

                Ian

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

                Comment


                • #9
                  Ian --
                  Yesterday I tested your fragment - Err57, like I described.
                  I think, that on your PC program hangs, because, when Windows started, it defined that there is a network connection through network card, started a driver, and don't expect that you can turn off a cable (imagine a reaction of Windows, if without restart you will open a block and turn off a cable from motherboard to HDD or floppy).

                  If you want correct experiment on your PC, turn off cable, REBOOT Windows and start a program.


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

                  Comment


                  • #10
                    Semen,
                    Your posting put me onto the right track and I discovered that if I just leave the program, then it will timeout at 65 seconds.

                    In my test program (above) I found that without a network connection the test program would return after about 5 seconds if there was no entry placed in the text field, if there was any entry in the text field (even garbage) then it would take 65 seconds to return.

                    I just wasn't patient enough but this timeout seems to be something to do with the windows api and is not controllable from PB.

                    Thank you very much for pointing me in the right direction.

                    Ian

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

                    Comment


                    • #11
                      I experienced a very similiar feature like this...had nothing to do with PB or the Win API...

                      Is your network ethernet or Token ring?
                      Token ring, pull the cable, you MUST reboot (Power off is good).
                      Ethernet, pull, put back in, works fine...

                      But, the key is hte 65 seconds and 5 seconds without garbage.


                      lets assume something, that the garbage in that field is a host name field....what makes 65 seconds different than 5 seconds?

                      In MS Windows (All) Netbios GENERALLY takes 60 seconds to time out, depending on your configuration. If you use Wins, it's generally set at 60 seconds by default....Therefore you are not resolving a name, which Wins/netbios WILL do whether you want it to or not...

                      Key to resolving MY issue was putting a STATIC IP address in the box to test with, and since LOCAL preferences override any DHCP you can also test this way....well, connection happened in 5 seconds instead of 65 seconds and problem was resolved, or at least pointed that DHCP was using WINS for host resolution...


                      And maybe NONE of that is applicable in your case, but it was so much like mine that i thought I'd post this..


                      Scott

                      ------------------
                      Scott
                      mailto:[email protected][email protected]</A>
                      Scott Turchin
                      MCSE, MCP+I
                      http://www.tngbbs.com
                      ----------------------
                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                      Comment


                      • #12
                        Thanks Scott,
                        It all helps in understanding what's going on and I can tell my boss this when he asks why it 'hangs'.

                        Ideally it would return instantly and say "You're not connected to the Internet!" but we all have to compromise sometimes and this is workable.

                        Frankly I think we're very lucky to have the PB compilers and functions such as the TCP functions make it very powerful.

                        Thanks

                        Ian

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

                        Comment

                        Working...
                        X