Page 1 of 1

TSocket Question

Posted: Thu Oct 04, 2012 11:20 am
by PeterHarmes
Hi,

I'm trying to connect to a windows socket & although my test routine is working, I dont seem to be able to check if i'm connected.

I have a public variable called lConnected that is initially set to .F. - this is set to true in bConnect, but when i try to reference it, it always returns .f. - the senddata & getdata routines all work fine.

Is there a better way to detect if i'm connected?

Code: Select all


STATIC FUNCTION SocketTest 
    LOCAL mTimer   := 0
    PRIVATE oSocket  := TSocket():New(8888)

    oSocket:bRead := { | oSocket | Msginfo( oSocket:GetData() )  }
    
    oSocket:bConnect := { || lConnected := .T. }

    oSocket:Connect( "192.168.69.92" ) // use the server IP address here
    
    DO WHILE !lConnected .AND. mTimer < 999999
        mTimer++
    ENDDO
    
    IF lConnected
        oSocket:SendData( "Hello" )
    
        ThreadSleep(1000)
        IF MsgYesNo("Quit?")
            RETU NIL 
        ENDIF 
    ELSE 
        ? "Not Connected" 
    ENDIF 
RETURN NIL

 
Thanks in advance

Pete

Re: TSocket Question

Posted: Wed Oct 24, 2012 8:21 am
by PeterHarmes
Hi,

Anyone have any ideas?

Best regards,

Pete

Re: TSocket Question

Posted: Wed Oct 24, 2012 11:02 am
by Antonio Linares
Peter,

FWH Class TSocket requires that there is a defined main window. There is no need to wait in a loop.

Please review FWH\samples\sockcli.prg

Re: TSocket Question

Posted: Wed Oct 24, 2012 9:49 pm
by FiveWiDi
Antonio Linares wrote:Peter,

FWH Class TSocket requires that there is a defined main window. There is no need to wait in a loop.

Please review FWH\samples\sockcli.prg
Hola Antonio,

Eso que comentas de la clase TSocket es aplicable a la clase HB_WhatsApp?

Para enviar WhastApp con la clase que menciono, debería funcionar desde un entorno MDI?

Saludos,
Carlos G.