Dear Enrico,
HB_CE has not this lib. Is there another TSocket class samples for my case?
I try as following but it doesn't work.
#include "FWCE.ch"
static oWnd, oSocket, cReadData
function Main()
local oBtn1, oBtn2, oBtn3, oBtn4, oGet
local cTbl := space(4)
DEFINE WINDOW oWnd TITLE '192.168.0.238'
@ 10, 100 GET oGet VAR cTbl SIZE 60, 18 PIXEL
@ 2, 2 BUTTON oBtn1 PROMPT "Connect" ;
ACTION (Client( oBtn1, oBtn2, oBtn3, oBtn4 )) SIZE 80, 20
@ 4, 2 BUTTON oBtn2 PROMPT "SendData" ;
ACTION (SendReq(oSocket,oGet,@cTbl), oGet:SetFocus()) ;
SIZE 80, 20
@ 6, 2 BUTTON oBtn3 PROMPT "ReadData" ;
ACTION MsgInfo(cReadData) SIZE 80, 20
@ 8, 2 BUTTON oBtn4 PROMPT "HostName" ;
ACTION MsgInfo( GetHostName() ) SIZE 80, 20
oBtn2:Disable()
oBtn3:Disable()
oBtn4:Disable()
ACTIVATE WINDOW oWnd
oSocket:End()
return nil
function Client( oBtn1, oBtn2, oBtn3, oBtn4 )
oSocket = TSocket():New( 2000 )
oSocket:bRead = { | oSocket | OnRead( oSocket ) }
// Never use a MsgInfo() here because it hangs Windows!!!
oSocket:bConnect = { || oBtn1:Disable(), oBtn2:Enable(), oBtn3:Enable(), oBtn4:Enable() }
oSocket:bClose = { || MsgInfo( "Server has closed!" ) }
oSocket:Connect( "192.168.0.238" ) // use the server IP address here
return nil
function SendFile()
MemoWrit( CurDir() + "\test.txt", "This is a file test" )
oSocket:SendData( "SENDFILE test.txt" )
SysRefresh()
oSocket:SendFile( CurDir() + "\test.txt" )
oSocket:End()
MsgInfo( "File sent" )
return nil
*---------------*
Function SendReq(oSocket,oGet, cTbl)
local nSec := seconds()
Default cTbl := '012 '
oSocket:SendData( "TBL 01"+cTbl )
do while empty(cReadData) .and. nSec+3 >= seconds()
end
cTbl := space(4)
oGet:Refresh()
return !empty(cReadData)
*--------------*
Function OnRead( oSocket )
local cGetData := oSocket:GetData()
cReadData := cGetData
// MsgInfo( cReadData )
return nil
Best regards,
Dutch