>All I want to do is use "Net.lib"s socket API to get a given URLs HTML
>contents back.

Give this a try.

Regards,
Steve Mann

# # #

This part is semi-pseudo code:

TCPSocketOpen ( netLibRefNum, &socket );
TCPSocketConnect ( netLibRefNum, socket, ipAddress, HS_SERVER_PORT );
UInt16  numBytesSent = 0;
Char *  urlP = "GET /whatever\n\n";  // valid HTTP GET request
TCPSend ( netLibRefNum, socket, urlP, &numBytesSent);
Int16   numBytesReceived = 0;
numBytesReceived = TCPReceive ( netLibRefNum, socket, response );
TCPSocketClose ( netLibRefNum, socket );

This is real code.

/***********************************************************************
* FUNCTION:     TCPSend
***********************************************************************/
static Err              TCPSend
(
        UInt16          netLibRefNum,
        NetSocketRef    sock,
        Char *          data,
        UInt16 *                bytesSent
)
{
        Int16   numBytesSent;
        Int16   numBytesToSend = StrLen ( data );
        Err     err;
        Int32   timeOut = NETLIB_SLOW_TIMEOUT * SysTicksPerSecond ();

        *bytesSent = 0;
        do {
                numBytesSent = NetLibSend (
                        netLibRefNum, sock, data, ( UInt16 ) numBytesToSend, 0,
                        NULL, 0, timeOut, &err) ;
                if ( numBytesSent > 0 )
                {
                        numBytesToSend -= numBytesSent;
                        data += numBytesSent;
                        *bytesSent += ( UInt16 ) numBytesSent;
                }
        } while ( numBytesSent > 0 && numBytesToSend > 0 );

        if ( numBytesSent == 0 )
                // ERROR
        else if ( numBytesSent < 0 )
                // ERROR
        return err;
}


/***********************************************************************
* FUNCTION:    TCPReceive
***********************************************************************/
static Int16 TCPReceive
(
        UInt16          netLibRefNum,
        NetSocketRef    sock,
        Char *          data
)
{
        Int16           totalBytesReceived      = 0;
        Int16           bytesToReceive          = ( Int16 ) 
MemPtrSize ( data );
        Int16           bytesReceived           = 0;
        Err             err;
        Int32           timeOut = NETLIB_SLOW_TIMEOUT * SysTicksPerSecond ();

        do
        {
                bytesReceived = NetLibReceive (
                        netLibRefNum, sock, data, ( UInt16 ) bytesToReceive, 0,
                        NULL, 0, timeOut, &err );
                if ( bytesReceived > 0 )
                {
                        bytesToReceive -= bytesReceived;
                        data += bytesReceived;
                        totalBytesReceived += bytesReceived;
                }
        } while ( bytesReceived > 0 && bytesToReceive > 0 );

        return totalBytesReceived;
}


-- 
Creative Digital Publishing Inc.
1315 Palm Street, San Luis Obispo, CA 93401-3117
-------------------------------------------
805.784.9461              805.784.9462 (fax)
[EMAIL PROTECTED]       http://www.cdpubs.com

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to