Article View: pilot.programmer
Article #13NetLibSend: Works on simulator, not on device, but returns no error
From: Tubby Bartles
Date: Sun, 11 Jan 2004 20:32
Date: Sun, 11 Jan 2004 20:32
134 lines
5209 bytes
5209 bytes
I'm running into a frustrating problem with NetLib.
The following code works on the simulator perfectly. On the actual
Treo device, it returns no errors. However, the string that is sent
never arrives at the server (so the read blocks, since there's nothing
sent back). I've verified this by looking at the server logs.
The NetLib is open (and the Treo starts up and completes its
"connection tot he network" dialog). The IP address returns correctly
(I've had it print out and verified by decoding the bytecode back to
x.x.x.x format). All the SysDelay is just so I can see the error
messages and know exactly what's happening.
Alternatively, if you have an example of NetLib code that works to
send/receive on the Treo 600, I'd love to see it. I'm trying to avoid
using the HS_HTTP libraries since that limits the usefulness of the
app specifically to the Treo 600, and won't work on other PalmOS
smartphones (Kyocera, Samsung, Treo 180/270/300, Tungsten, etc.).
-- Kevin
/* Get the address */
set_status( "Getting IP Address..." );
if ((site[0] >= '0') && (site[0] <= '9')) {
IPaddress = NetLibAddrAToIN( netlibid, site );
} else {
hostresult = NetLibGetHostByName( netlibid, site, &buf, timeout,
&error );
if (hostresult == 0) {
error = 1;
} else {
IPaddress = buf.address[0];
}
}
if (error == 0) {
set_status( "Opening socket..." );
socket = NetLibSocketOpen( netlibid,
netSocketAddrINET,
netSocketTypeStream,
netSocketProtoIPTCP,
timeout,
&error );
}
if (error == 0) {
/* Connect to the socket */
MemSet(&destAddr, sizeof(destAddr), 0);
destAddr.family = netSocketAddrINET;
destAddr.port = 80; // Also tried HToNS port as well
destAddr.addr = IPaddress;
connected = 0;
error = netErrWouldBlock; result = -1;
while ((result != 0) &&
((error == netErrWouldBlock) ||
(error == netErrSocketBusy)))
{
result = NetLibSocketConnect(netlibid,// Network library
socket, // Socket reference
(NetSocketAddrType*)&destAddr, // Destination
address
sizeof(destAddr), // Length of
destAddr
timeout, // Timeout
&error // Error result
);
SysTaskDelay( insert_delay );
}
if ((result == 0) || (error = netErrSocketAlreadyConnected)) {
result = 0;
error = 0;
}
} else {
netfunc_Error( "Error get hostname:", (UInt32)error );
return error;
}
if (error == 0) {
set_status( "Waiting to write..." );
// Wait for the socket to be ready for a write
error = netfunc_WaitWrite();
if (error) {
netfunc_Error( "Error waiting to write:", (UInt32) error);
return error;
}
set_status( "Writing..." );
/* Send the string */
bufLen = StrLen( send_string );
sentBytes = 0;;
while ((sentBytes < bufLen) && (error == 0)) {
result = NetLibSend (netlibid, // Network library
socket, // Socket reference
send_string + sentBytes, // Buffer to send
bufLen - sentBytes, // Bytes to send from buffer
0, // Flags
NULL, // Destination address
0, // Length of destination address
timeout, // Timeout
&error // Error result
);
SysTaskDelay( insert_delay );
if (result != -1) error = 0;
sentBytes += result;
}
} else {
netfunc_Error( "Error connect:", (UInt32)error );
return error;
}
if (error) {
netfunc_Error( "Error write:", (UInt32)error );
return error;
} else {
SysTaskDelay( insert_delay );
netfunc_ReadAll();
}
// AT THIS POINT, THE READ BLOCKS BECAUSE THERE?S NOTHING TO
// READ. A CHECK OF SERVER LOGS SHOWS NOTHING WAS RECEIVED
// FROM THE DEVICE. ON THE SIMULATOR, EVERYTHING WORKS
// PERFECTLY.
Technical Details
Message-ID:
<e7cab969.0401111232.3c3cadb0@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews2.google.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109d41,722e0fb5fdb7bca3,start X-Google-Attributes: gid109d41,public X-Google-Thread: 10baa0,722e0fb5fdb7bca3,start X-Google-Attributes: gid10baa0,public X-Google-Thread: 10c638,722e0fb5fdb7bca3,start X-Google-Attributes: gid10c638,public X-Google-ArrivalTime: 2004-01-11 12:32:52 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews2.google.com!not-for-mail From: tubby_bartles@hotmail.com (Tubby Bartles) Newsgroups: pilot.programmer,codewarrior.palm,pilot.programmer.codewarrior Subject: NetLibSend: Works on simulator, not on device, but returns no error Date: 11 Jan 2004 12:32:51 -0800 Organization: http://groups.google.com Lines: 134 Message-ID: <e7cab969.0401111232.3c3cadb0@posting.google.com> NNTP-Posting-Host: 66.159.224.110 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1073853172 32679 127.0.0.1 (11 Jan 2004 20:32:52 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 11 Jan 2004 20:32:52 +0000 (UTC)