Hello All,
We have a Palm product, which tries to talk to a
server every now using the NetLib.  As long as the
connection is active, everything looks to be working
fine (may be shortly after a wireless hotsync or
naviagtion to a web-site) on a Tungsten C via WiFi. 
However, when the connection timesout, it is having
problem re-establishing the connection the first time
it tries.

If the user tries to retransmit the message, chances
are it works.  (sometimes, they need to try it a 3rd
time, before it really works).  Not sure, what could I
be doing wrong which is not causing it to work the
first time.  Attached is a snippet of the code:

***************************************

error = NetLibOpen(libRefNum, &ifErrs);
if (error && (error != netErrAlreadyOpen)) {
    FrmCustomAlert(ErrorAlt, "Error In NetLibOpen", "
- ", StrIToA(tempStr, error));
    NetLibClose(libRefNum, false);
    return error;
} else {
    UInt8 allUp;
    error = NetLibConnectionRefresh(libRefNum, true,
&allUp, &ifErrs);
}
if(ifErrs == netErrPrefNotFound) {
    FrmCustomAlert(ErrorAlt, "Network Setup
Incomplete", " - ", "Switch to the Network preference
panel and check your setup.");
    NetLibClose(libRefNum, false);
    return ifErrs;
} else if(ifErrs) {
    UInt16 cfgIndex;
    error = NetLibConfigIndexFromName(libRefNum,
(NetConfigNameType*)netCfgNameDefWireless, &cfgIndex);
    error = NetLibOpenConfig(libRefNum, cfgIndex,
(UInt32)0, &ifErrs);
    FrmCustomAlert(ErrorAlt, "After NetLibOpenConfig",
" - ", StrIToA(tempStr, ifErrs));
    switch(error) {
        Case memErrNotEnoughSpace:
            FrmCustomAlert(ErrorAlt, "Not Enough
Memory - NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrAlreadyOpen:
            FrmCustomAlert(ErrorAlt, "Already Open -
NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrBufTooSmall:
            FrmCustomAlert(ErrorAlt, "Buffer Too Small
- NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrConfigAliasErr:
            FrmCustomAlert(ErrorAlt, "Configuration
Alias Error - NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrConfigCantDelete:
            FrmCustomAlert(ErrorAlt, "Configuration
Can't Delete - NetLibOpenConfig", 0, 0);
            break;
        
        Case netErrConfigEmpty:
            FrmCustomAlert(ErrorAlt, "Configuration
Empty - NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrConfigNotFound:
            FrmCustomAlert(ErrorAlt, "Configuration
Not Found - NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrInterfaceNotFound:
            FrmCustomAlert(ErrorAlt, "Interface Not
Found - NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrOutOfCmdBlocks:
            FrmCustomAlert(ErrorAlt, "Out of Command
Blocks - NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrOutOfMemory:
            FrmCustomAlert(ErrorAlt, "Out of Memory -
NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrNoInterfaces:
            FrmCustomAlert(ErrorAlt, "No Interfaces -
NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrParamErr:
            FrmCustomAlert(ErrorAlt, "Parameter Error
- NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrPrefNotFound:
            FrmCustomAlert(ErrorAlt, "Preference Not
Found - NetLibOpenConfig", 0, 0);
            break;
            
        Case netErrTimeout:
            FrmCustomAlert(ErrorAlt, "Timeout -
NetLibOpenConfig", 0, 0);
            break;
    }
}

.........
........
......
........
........

hostP = NetLibGetHostByName(netRefNum,
url.serverAddress, &hostBuffer, timeout, &errVal);

if(hostP) {
        FrmCustomAlert(ErrorAlt, "Before
NetLibSocketOpen", " - ", StrIToA(tempStr, errVal));
    netSockRef = NetLibSocketOpen(netRefNum,
netSocketAddrINET, netSocketTypeStream,
netSocketProtoIPTCP, /*timeout*/5, &errVal);
        FrmCustomAlert(ErrorAlt, "After
NetLibSocketOpen", " - ", StrIToA(tempStr, errVal));
    if(netSockRef != -1) {
        MemSet(&sockAddress, sizeof(sockAddress), 0);
        sockAddress.family = netSocketAddrINET;
        sockAddress.port = NetHToNS(port_number);
        sockAddress.addr = hostBuffer.address[0];
        WWWSetSocketStatus( wwwStatusConnecting );
            FrmCustomAlert(ErrorAlt, "Before
NetLibSocketConnect", " - ", StrIToA(tempStr,
errVal));
        Int16 ret = NetLibSocketConnect(netRefNum,
netSockRef, (NetSocketAddrType*)&sockAddress,
sizeof(sockAddress), timeout, &errVal);
            FrmCustomAlert(ErrorAlt, "After
NetLibSocketConnect", " - ", StrIToA(tempStr,
errVal));
        if(errVal == netErrSocketAlreadyConnected) {
            NetLibSocketClose(netRefNum, netSockRef,
timeout, &errVal);
            ret = NetLibSocketConnect(netRefNum,
netSockRef, (NetSocketAddrType*)&sockAddress,
sizeof(sockAddress), timeout, &errVal);
            FrmCustomAlert(ErrorAlt, "After
NetLibSocketConnect", " - ", StrIToA(tempStr,
errVal));
        }
    } else {
        switch(errVal) {
            Case netErrTimeout:
                FrmCustomAlert(ErrorAlt, "TimeOut -
NetLibConnect", 0, 0);
                break;
                
            Case netErrNotOpen:
                FrmCustomAlert(ErrorAlt, "NotOpen -
NetLibConnect", 0, 0);
                break;
                
            Case netErrParamErr:
                FrmCustomAlert(ErrorAlt, "ParamErr -
NetLibConnect", 0, 0);
                break;
                
            Case netErrNoMoreSockets:
                FrmCustomAlert(ErrorAlt,
"NoMoreSockets - NetLibConnect", 0, 0);
                break;
                
            Case netErrOutOfCmdBlocks:
                FrmCustomAlert(ErrorAlt,
"OutOfCmdBlocks - NetLibConnect", 0, 0);
                break;
                
            Case netErrOutOfMemory:
                FrmCustomAlert(ErrorAlt, "OutOfMemory
- NetLibConnect", 0, 0);
                break;
        }
    }
} else {
    switch(errVal) {
        Case netErrTimeout:
            FrmCustomAlert(ErrorAlt, "TimeOut -
NetLibConnect", 0, 0);
            break;
                
        Case netErrNotOpen:
            FrmCustomAlert(ErrorAlt, "NotOpen -
NetLibConnect", 0, 0);
            break;
                
        Case netErrOutOfMemory:
            FrmCustomAlert(ErrorAlt, "OutOfMemory -
NetLibConnect", 0, 0);
            break;

        Case netErrDNSNameTooLong:
        Case netErrDNSBadName:
        Case netErrDNSLabelTooLong:
        Case netErrDNSAllocationFailure:
        Case netErrDNSTimeout:
        Case netErrDNSUnreachable:
        Case netErrDNSFormat:
        Case netErrDNSServerFailure:
        Case netErrDNSNonexistantName:
        Case netErrDNSNIY:
        Case netErrDNSRefused:
        Case netErrDNSImpossible:
        Case netErrDNSNoRRS:
        Case netErrDNSAborted:
        Case netErrDNSBadProtocol:
        Case netErrDNSTruncated:
        Case netErrDNSNoRecursion:
        Case netErrDNSIrrelevant:
        Case netErrDNSNotInLocalCache:
        Case netErrDNSNoPort:
            FrmCustomAlert(ErrorAlt, "DNS Error -
NetLibConnect", 0, 0);
            break;
    }
}

*********************************

Everything seems to be working fine until the call to
the NetLibGetHostByName is done.  This is returning a
4626 (which I believe is netErrPrefNotFound) and
obviously all subsequent calls are failing.  On trying
the same transmission one more time, most of the
times, it succeeds with no errors (very rarely though,
it fails the 2nd time too with the same error).  The
other interesting thing is once this transmission
fails, when I go to Preferences->Network and check the
status, it shows as if it is connected.

When I try the wireless hotsync, with the connection
not established, the connection gets established the
very first time and it all works.  The same with even
the browser.  Not sure, where I'm doing wrong and how
I can fix it.

I'ld appreciate any help in this regard.  I've tried
reading the documentation so many times and tried so
many things, I'm not sure, what else can be tried
other than seeking some help from the Gurus.

-Kalyan


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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

Reply via email to