Daniel Garcia-Gil
Posts: 2365 Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:
Post
by Daniel Garcia-Gil » Mon May 09, 2011 7:15 pm
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
Horizon
Posts: 1323 Joined: Fri May 23, 2008 1:33 pm
Has thanked: 3 times
Post
by Horizon » Tue May 10, 2011 6:45 am
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 & MSVC 2022 & FWH 23.04
Daniel Garcia-Gil
Posts: 2365 Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:
Post
by Daniel Garcia-Gil » Tue May 10, 2011 12:56 pm
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
Horizon
Posts: 1323 Joined: Fri May 23, 2008 1:33 pm
Has thanked: 3 times
Post
by Horizon » Tue May 10, 2011 3:12 pm
Thanks, I trying now.
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Horizon
Posts: 1323 Joined: Fri May 23, 2008 1:33 pm
Has thanked: 3 times
Post
by Horizon » Tue May 10, 2011 7:02 pm
Hi Daniel,
This is my last SockCli.prg.
Code: Select all | Expand
// Socket server connection sample #include "FiveWin.ch" #define nWaitTime 10000 static oWnd, oSocket, oTimer, nTryfunction 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 oWndreturn 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 & MSVC 2022 & FWH 23.04
Horizon
Posts: 1323 Joined: Fri May 23, 2008 1:33 pm
Has thanked: 3 times
Post
by Horizon » Tue May 10, 2011 8:02 pm
Yes. I also think to use cargo if its really connected.
Thank you very much.
Code: Select all | Expand
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 & MSVC 2022 & FWH 23.04