Hi
Maybe this small test will help someone to see how easy it is to read and write
non DBF files using netio RPC.
Regards
Alex
/*
* $Id: netiot04.prg 14415 2010-04-30 09:39:25Z druzus $
*/
/*
* Harbour Project source code:
* demonstration/test code for alternative RDD IO API, RPC and
* asynchronous data streams in NETIO
*
* Copyright 2010 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org
*
*/
/* net:127.0.0.1:2941:topsecret:data/_tst_ */
#include "fileio.ch"
#define DBSERVER "127.0.0.1"
#define DBPORT 2941
request FILE
request FCREATE
request FOPEN
request FSEEK
request FWRITE
request NETFREAD
request FCLOSE
proc main()
local pSockSrv
local cFile := "hello.txt"
local nHandle
local cData := "Hello HBNetIO"
local lExists
local cBuffer
pSockSrv := netio_mtserver( DBPORT,,, /* RPC */ .T. )
if empty( pSockSrv )
? "Cannot start NETIO server !!!"
wait "Press any key to exit..."
quit
endif
? "NETIO server activated."
hb_idleSleep( 0.1 )
?
? "NETIO_CONNECT():", netio_connect( DBSERVER, DBPORT )
?
? "FILE:", lExists := netio_funcexec( "file", cFile )
if lExists
? "FOPEN:", nHandle := netio_funcexec( "fopen", cFile, FO_WRITE )
? "FSEEK:", netio_funcexec( "fseek", nHandle, 0, FS_END )
else
? "FCREATE:", nHandle := netio_funcexec( "fcreate", cFile )
endif
? "FWRITE:", netio_funcexec( "fwrite", nHandle, time() )
? "FWRITE:", netio_funcexec( "fwrite", nHandle, " " + cData )
cData := chr(13) + chr(10)
? "FWRITE:", netio_funcexec( "fwrite", nHandle, cData )
? "FCLOSE:", netio_funcexec( "fclose", nHandle )
?
? "FOPEN:", nHandle := netio_funcexec( "fopen", cFile, FO_READ )
while !empty( cBuffer := netio_funcexec( "netfread", nHandle ) )
? cBuffer
end
? "FCLOSE:", netio_funcexec( "fclose", nHandle )
?
? "stopping the server..."
netio_serverstop( pSockSrv, .t. )
return
function netfread( nHandle )
local cBuffer := space( 1024 )
local nRead
if ( nRead := fread( nHandle, @cBuffer, 1024 ) ) <= 0
return NIL
endif
return left( cBuffer, nRead )
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour