Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Com Server Process

Status
Not open for further replies.

AlastairP

Technical User
Feb 8, 2011
286
AU
I am trying to confirm a FTP connection -
When the connection is OK, I get a quick response, all is good.
When the connection is no good or the wrong host is provided it takes a long time for the connection to return failed.
This causes a hang.
So I made a out-of-process com exe to run the task, but I am still having similar issues.
I could wait the amount of time, yes and then continue. This will work, but the wait time is somewhat excessive.

Once the reference to the com exe is created, it still needs to wait while it runs its task, before it can be released.
Is there any other solution to checking for a remote FTP connection? Something like 'If you don't respond in 'x' amount of seconds, then the connection failed'

I am using WinInet at the moment.

Alastair
 
Hi Alastair,

Checking if an IP connection is valid can also be done via iphlpapi like this:

Code:
FUNCTION isAlive
LPARAMETERS vIpNum, vSilent

    * declaration 
    DECLARE INTEGER GetRTTAndHopCount IN Iphlpapi;
       INTEGER DestIpAddress, LONG @HopCount,;
       INTEGER MaxHops, LONG @RTT
    DECLARE INTEGER inet_addr IN ws2_32 STRING cp

    * variables
    LOCAL lnDst, lnHop, lnRTT, llReturn

    lnDst        = inet_addr(m.vIpnum)
    llReturn    = .F.
    STORE 0 TO lnHop, lnRTT

    * ping IP and if return=0 ping was negative
    IF GetRTTAndHopCount(lnDst, @lnHop, 5, @lnRTT) = 0

        TEXT TO lcMsg TEXTMERGE NOSHOW PRETEXT 3
            IP-adress <<m.vIpnum>> doesn't respond
        ENDTEXT
    
    * otherwise IP is accessible
    ELSE

        TEXT TO lcMsg TEXTMERGE NOSHOW PRETEXT 3
            IP-adress <<m.vIpnum>> response
            (<<m.lnRTT>> MSek / <<m.lnHop>> Hops)
        ENDTEXT
        llReturn = .T.
      
    ENDIF

    * if message is allowed, then show response infos
    IF NOT vSilent
        MESSAGEBOX(lcMsg,0+64+0,[IP reponse time])
    ENDIF

    * returnvalue .T. = successful, .F. = no response
    RETURN llReturn

ENDFUNC

Can't remember how long a negative response will last, though. I used that code in ~2007/2008 and remembered, that I had placed it in my blog sometime.

HTH

-Tom
 
I guess that'll help.

The idea an out of process COM Server will run in parallel also isn't wrong, but the nature of calls to its methods still is only returning after the method executed. The simplest method to create a separate EXE that runs in parallel does something and quit is to create a normal EXE and call it with RUN /N.

Otherwise, your method - say ftp_connect - should return before it connects, which is possible if you create a timer that does the real code in its Timer event, that is set to a small interval and that is releasing itself at the end of its Timer, the ftp_connect method then creates this timer, enables it and returns. Not long ago I also established an EXE COM Server to separate something from the main application this way, too.

In case Of FTPing the shoot off process might be enough, when you include a full batch of commands to do, that principle also is used in Craig Boyds VFPConnection.FLL:
Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top