| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Returns the number of bytes transferred in the last sockets operation
INetCount( <pSocket> ) --> nBytes
The function returns the number of bytes transferred in the last sockets operation as a numeric value.
The function is used to determine how many bytes are read from the socket <pSocket> with INetRecv(), or written to it with INetSend().
| See also: | INetConnect(), INetDataReady(), INetRecv(), INetRecvAll(), INetSend(), INetSendAll() |
| Category: | Internet functions , Sockets functions , xHarbour extensions |
| Source: | vm\inet.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example uses INetCount() to detect the end of a file download
// from a HTTP server.
PROCEDURE Main
LOCAL pSocket, cBuffer, nBytes, cRequest, cResponse
CLS
// initialize sockets system and connect to server
INetInit()
pSocket := INetConnect( "www.xharbour.com", 80 )
IF INetErrorCode( pSocket ) <> 0
? "Socket error:", INetErrorDesc( pSocket )
INetCleanUp()
QUIT
ENDIF
// send HTTP request to server
cRequest := "GET / HTTP/1.1" + INetCRLF() + ;
"Host: www.xharbour.com" + INetCRLF() + ;
"User-Agent: HTTP-Test-Program" + INetCRLF() + ;
INetCRLF()
INetSend( pSocket, cRequest )
? "Bytes sent:", INetCount( pSocket )
cResponse:= ""
// get HTTP response from server
DO WHILE INetCount( pSocket) > 0
cBuffer := Space( 4096 )
INetRecv( pSocket, @cBuffer )
nBytes := INetCount( pSocket )
? "Bytes received:", nBytes
cResponse += Left( cBuffer, nBytes )
ENDDO
// disconnect and cleanup memory
INetClose( pSocket )
INetCleanUp()
// save response
Memowrit( "xharbour.txt", cResponse )
? "Data written to file: xHarbour.txt"
RETURN
http://www.xHarbour.com