xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

INetCount()

Returns the number of bytes transferred in the last sockets operation

Syntax

INetCount( <pSocket> ) --> nBytes

Arguments

<pSocket>
This is a pointer to a socket as returned by INetConnect() or INetAccept().

Return

The function returns the number of bytes transferred in the last sockets operation as a numeric value.

Description

The function is used to determine how many bytes are read from the socket <pSocket> with INetRecv(), or written to it with INetSend().

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe