hi all,
i am trying to get data from a the specified URL on PalmOS Simulator5.1 , using
the NetMgr.h
i have written this code : all functions run successfully and return no error
..but i am unable to receive data.
// Find the network library
error=SysLibFind("Net.lib", &AppNetRefnum); // returns 0 if no error
if (error==0)
{ FldInsert(fldptr1, "could find Net.lib ", 19); }
else
{ FldInsert(fldptr1, "could not find Net.lib", 22); }
// Open the network library
error = NetLibOpen(AppNetRefnum, &ifErrs);
if(error==0)
{ FldInsert(fldptr1, "could open Net.lib ", 19); }
else
{ FldInsert(fldptr1, "could not open Net.lib",22); }
if (ifErrs || (error && error != netErrAlreadyOpen))
{
NetLibClose(AppNetRefnum, false);
return 0 ;
}
MemSet(&destAddr, sizeof(destAddr), 0);
destAddr.family = netSocketAddrINET;
destAddr.port = 80;
hostInfoP = NetLibGetHostByNameAppNetRefnum,"http://www.xyz.com"/*the URL of my
company server comes here*/,hostInfoBufP, AppNetTimeout, &errP);
if(hostInfoP !=0)//no error
{
IPaddressP = (NetIPAddr*)hostInfoBufP->addressList[0];
destAddr.addr = NetNToHL(*IPaddressP);
FldInsert(fldptr1, "gethostbyname successful ", 25);
}
// Open a socket
socket = NetLibSocketOpen(AppNetRefnum, netSocketAddrINET, netSocketTypeStream,
netSocketProtoIPTCP,-1,&error);
/*parameters 1-Network Library,2-Address domain,3-socket
type,4-protocol,5-timeout,6-error result*/
if (error)
{ NetLibClose(AppNetRefnum, false);
return 0 ;
}
else{ FldInsert(fldptr1, "socket opened ", 14); }
result = NetLibSocketConnect(AppNetRefnum , socket , (NetSocketAddrType
*)&destAddr , sizeof(destAddr) , AppNetTimeout ,&error);
if (result == 0)
{ FldInsert(fldptr1, "socket connects ", 16); }
else
{
FldInsert(fldptr1, "socket does not connect ", 24);
NetLibSocketClose (AppNetRefnum, socket, -1,&error);
NetLibClose(AppNetRefnum, false);
return 0 ;
}
//send
/* i am sending here the URL i want to get data from...am i right here? so
parameter "buf" has the URL*/
/******************i am confused here********/
noOfBytes = NetLibSend(AppNetRefnum,socket , buf , bufLen , 0 , NULL , 0 ,
AppNetTimeout , & error );
if(noOfBytes!=0)
{
FldInsert(fldptr1, "data has been sent ", 19);
}
//recv
size = sizeof(destAddr);
result = NetLibReceive(AppNetRefnum , socket , &bufRecv , size , 0 ,
(NetSocketAddrType *)&destAddr , &size , -1 , &error );
if(result == 0)//no error
{
FldInsert(fldptr1, "data received ", 14);
FldInsert(fldptr, (char*)&bufRecv/*serverResponse*/, 256);
/* i want to insert in a field the data i get from our server i.e bufRecv, but
i get 0 value in this variable*/
/***************not able to receive data here**************/
}else{ FldInsert(fldptr1, "data not received ", 18); }
//close
NetLibSocketClose (AppNetRefnum,socket,-1, &error );
if(error == 0)
{ FldInsert(fldptr1, "socket closing ", 15); }
NetLibClose(AppNetRefnum, false);
return true;
}
all those who are working on internet application using NetMgr.h kindly
help...i am unable to find my fault..but there is one for sure..suggestions are
welcomed.
Thanks!
versha
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/