Tsocket Bug

User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Tsocket Bug

Post by Daniel Garcia-Gil »

Daniel Garcia-Gil wrote: With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK. ( you can call after connect, will see )
Yes is a normal error For use nonblocking socket... Windows doc api explain it
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: Tsocket Bug

Post by Horizon »

Daniel,

ıs it possible to set a timeout to give alert client that the connection has not been established when there is no message "ok"

Thanks,
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Tsocket Bug

Post by Daniel Garcia-Gil »

Hello

you can use a timer to call Connect() again if you got not a "ok", with max Retry options

1- initiate Retry variable
2- open timer
3- connect
4- if you get "ok" deactivate the timer, else try connect again until max retry is take (deactivate timer )

is only a idea
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: Tsocket Bug

Post by Horizon »

Thanks,

I trying now.
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: Tsocket Bug

Post by Horizon »

Hi Daniel,

This is my last SockCli.prg.

Code: Select all

// Socket server connection sample

#include "FiveWin.ch"

#define nWaitTime       10000

static oWnd, oSocket, oTimer, nTry

function Main()

   local oBar

   DEFINE WINDOW oWnd TITLE "Client socket"

   DEFINE BUTTONBAR oBar OF oWnd _3D

   DEFINE BUTTON OF oBar ACTION Client() TOOLTIP "Connect"
    
   DEFINE BUTTON OF oBar ;
      ACTION oSocket:SendData( "MSG This is a test" ) ;
      TOOLTIP "Send data"
      
   DEFINE BUTTON OF oBar ;
      ACTION SendFile() TOOLTIP "Send file"

   ACTIVATE WINDOW oWnd

return nil

function Client()
   
   if oSocket != NIL
      oSocket:End()
   endif
   oSocket = TSocket():New( 5000 )
   
   if oTimer != NIL
      oTimer:End()
   endif

     nTry := 1

   oSocket:bRead    = { | oSocket | HandleRecived( oSocket, oWnd ) }

   // Never use a MsgInfo() here because it hangs Windows!!!
   oSocket:bConnect = { || oWnd:SetText( "Socked Opened!" ) }

   oSocket:bClose   = { || MsgInfo( "Server has closed!" ) }

     Timer_Connect()    
    
     Define Timer oTimer Interval nWaitTime Action Timer_Connect() OF oWnd
   Activate Timer oTimer   

   
return nil

function Timer_Connect()
    IF nTry<4
        oWnd:SetText("Connection Try : "+ALLTRIM(STR(nTry)))
        oSocket:Connect( "127.0.0.1" )  
        nTry++
    ELSE 
        oTimer:End()
        oSocket:End()
        oWnd:SetText( "Socket Closed" )
        MsgInfo("Connection can NOT be ESTABLISHED")
  ENDIF 
return

function SendFile()

   local cFileName := cGetFile( "*.*", "Select a file to send by Internet" )

   if ! Empty( cFileName ) .and. File( cFileName )
      oSocket:SendData( "SENDFILE " + cFileName( cFileName ) )
      oSocket:SendFile( cFileName )
      MsgInfo( "File sent" )
   endif

return nil

function HandleRecived( oSocket, oWnd )

   local cData := oSocket:GetData()
   
   
   if cData = "ok"
      oWnd:SetText( "Connected!!" )
      oTimer:End()
   else 
      MsgInfo( cData )
   endif


return nil
 
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Tsocket Bug

Post by Daniel Garcia-Gil »

Hello

what's mean? all is working fine now?
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: Tsocket Bug

Post by Horizon »

Yes. I also think to use cargo if its really connected.

Thank you very much.


Code: Select all

function HandleRecived( oSocket, oWnd )

   local cData := oSocket:GetData()
   
   
   if cData = "ok"
      oWnd:SetText( "Connected!!" )
      oTimer:End()
      oSocket:cargo:=.t.   // it is connected.
   else 
      MsgInfo( cData )
   endif


return nil
 
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
Post Reply