You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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
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 --
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)
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.
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.
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.
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 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
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment