I've got some working INet lib code - this code assumes you're running on a
Palm VII:

//
// fetch a web page:
//
// Globals: ilibRefNum, inetH, connected 

DWord conv = ctpConvNone;
Word config;

if (SysLibFind("INet.lib", &ilibRefNum) != 0) {
        // library not there -- error message
        return;
}

if (INetLibConfigIndexFromName (ilibRefNum, (INetConfigNamePtr)
inetCfgNameCTPDefault, &config)) {
        // bad config
        return;
}

if (INetLibOpen (ilibRefNum, config, 0, NULL, 0, &inetH) != 0) {
        // error message
        return;
}

// Show signal strength meter
INetLibWiCmd (ilibRefNum, wiCmdInit, 140, 1);
INetLibWiCmd (ilibRefNum, wiCmdSetLocation, 76, 1);
INetLibWiCmd (ilibRefNum, wiCmdSetEnabled, 1, 1);

// turn off compression
INetLibSettingSet (ilibRefNum, inetH, inetSettingConvAlgorithm, &conv,
sizeof(conv));

// get up to 10kb back (NOTE: this doesn't seem to work)
conv = 10240;
INetLibSettingSet (ilibRefNum, inetH, inetSettingMaxRspSize, &conv,
sizeof(conv));

// open URL
// NOTE: URLPtr points to a URL string
INetLibURLOpen (ilibRefNum, inetH, (BytePtr)URLPtr,
        NULL, &sockH, -1, 0);
connected = true;                       // connected is a global

Once you do the fetch, you need to read the response. I do that using a
modified event loop:
static void EventLoop(void)
{
        Word error;
        EventType event;

        do {            
                if (connected) {
                        INetLibGetEvent (ilibRefNum, inetH, (INetEventType*)
&event, evtWaitForever);
                }
                else {
                        EvtGetEvent(&event, evtWaitForever);
                }
                if (! SysHandleEvent(&event))
                        if (! MenuHandleEvent(0, &event, &error))
                                if (! ApplicationHandleEvent(&event))
                                        FrmDispatchEvent(&event);

        } while (event.eType != appStopEvent);
}


The form handler handles INetLib events:

Boolean FormHandleEvent(EventPtr eventP) {
        Char ioBuf[TCPBUF];
        DWord inumAvail;
        Err err;

        switch (eventP->eType) {

        case inetSockReadyEvent:
                err = INetLibSockRead (ilibRefNum, sockH, 
                        (VoidPtr) ioBuf, TCPBUF-1, &inumAvail,
SysTicksPerSecond());
                if (err != 0) {
                        ShowStatus("inet timeout");     //debugging info --
a timeout isn't a fatal error
                        break;
                }
                if (inumAvail == 0) {
                        ShowStatus("inet eof");         // debugging info --
eof
                        INetLibClose (ilibRefNum, inetH);
                        INetLibWiCmd (ilibRefNum, wiCmdSetEnabled, 0, 1); //
turn off signal meter
                        connected = false;
                }
                else {
                        ShowStatus("inet READ");        // debugging info --
we got some data
                        ioBuf[inumAvail]='\0';          // null terminate
string
                        // do something with it
                }
                break;  
        // rest of handler...

This code fetches a web page in plain text (not the compressed encoded form
used by clipper) but it seems to only fetch the first 1kb, even though I
tell it to fetch up to 10kb. Any thoughts on that problem welcomed.

 ==-
John Schettino author of
Palm OS Programming For Dummies, http://schettino.tripod.com

Greg Pasquariello asks:
Anyone have a brief example of a working INet application? Mine has been
barfing all week, and I'm not sure why. Everything seems to work until I try
to read data, at which point I get various and sundry errors. 

Reply via email to