first error - If i give my domain name as www.xyz.com in NetLibGetHostByName , 
i get Palmsim.exe error . But if i give as http://www.xyz.com it doesnt?
which is the correct way?

second problem i have in my prog attached below do i need to call NetLibsend 
..if i just want to store data what i get from the website.should i use only 
NetLibReceive ?

third problem is in NetLibReceive ..where i get 0 bytes received.

i cant figure out my problem...i am new to network programming.


here is my bit of code : 
void functionget()
{
        NetSocketRef socket; 
        Err error; 
        UInt16 ifErrs; 
        Int16 result; 
        NetSocketAddrINType destAddr; 
        UInt16 AppNetRefnum;
        FieldType *fldptr;
        FieldType *fldptr1;
        NetHostInfoPtr hostInfoP;
        NetHostInfoBufPtr hostInfoBufP;
        NetIPAddr *IPaddressP;
        Int32 AppNetTimeout ;
        Int16 noOfBytes; 
                Int16 noOfBytes1; 
        const UInt16 bufLen = 16;


        char buf[bufLen] = "www.xyz.com";

                char output[100];

//      void * bufRecv;

        void *  str ;
                UInt16 *sizeP;
        UInt16 size;
        NetSocketLingerType SockLinger;

  fldptr = (FieldType *)GetObjectPtr(MainFldRetField);
  fldptr1 = (FieldType *)GetObjectPtr(MainFldReqField);

// Find the network library 

error = SysLibFind("Net.lib", &AppNetRefnum); // returns 0 if no error , finds 
in the network for this file
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); 

} 



MemSet(&destAddr, sizeof(destAddr), 0); 
    destAddr.family = netSocketAddrINET;
 // This should match the second argument to NetLibSocketOpen 
    destAddr.port = htons(80); 
    
    FldInsert(fldptr1, "memset ", 7);
// Open a socket 

   hostInfoBufP = 
      (NetHostInfoBufPtr) MemPtrNew (sizeof (NetHostInfoBufType));


hostInfoP = NetLibGetHostByName(AppNetRefnum,"www.xyz.com",hostInfoBufP, 
AppNetTimeout, &error);        

if(hostInfoP !=0)//no error
{

        IPaddressP = (NetIPAddr*)hostInfoBufP->addressList[0];
        destAddr.addr = NetNToHL(*IPaddressP);
        FldInsert(fldptr1, "gethostbyname successful ", 25);
}
else
{
        FldInsert(fldptr1, "gethostbyname not successful ", 29);
}



socket = NetLibSocketOpen(AppNetRefnum, netSocketAddrINET, netSocketTypeStream, 
netSocketProtoIPTCP,-1,&error); 


if(socket==-1)
{
                FldInsert(fldptr1, "socket closed ", 14);
  
}

        if(error == 0)
        {
                FldInsert(fldptr1, "socket opened ", 14);
        }
        else
        {
                FldInsert(fldptr1, "socket closed ", 14);
        }


SockLinger.onOff = true;
SockLinger.time = 0;//to turn socklinger off it is onOff = 


result = NetLibSocketOptionSet(AppNetRefnum ,  socket , netSocketOptLevelSocket 
, netSocketOptSockLinger , &SockLinger , sizeof(SockLinger) , -1 , &error );


                
result = NetLibSocketConnect(AppNetRefnum , socket , (NetSocketAddrType 
*)&destAddr , sizeof(destAddr) , /*AppNetTimeout*/-1 , &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); 
        
        }

      

//send 
noOfBytes = NetLibSend(AppNetRefnum,socket , buf  , bufLen , 0 , NULL , 0 , 
AppNetTimeout , & error );
if(noOfBytes!=0)
{
// FrmCustomAlert(AlertAlert,(char*)&buf ,NULL,NULL);
 FldInsert(fldptr1, "datasent", 8);

}

//recv
size = sizeof(destAddr);

str  = MemPtrNew( sizeof( char ) * 500 );


result = NetLibReceive(AppNetRefnum , socket ,&str  , 1000 , 0  , 
(NetSocketAddrType *)&destAddr , &size, -1 , &error );


if(error == 0)//no error
{
   FrmCustomAlert(AlertAlert,(char*)str ,NULL,NULL);
            
}else{
        FldInsert(fldptr1, "data not received ", 18);
}

//close
        
 NetLibSocketClose (AppNetRefnum,socket,-1, &error ); 
if(error == 0)
  {
                        FldInsert(fldptr1, " socketclosing", 14);
  }
  result = NetLibClose(AppNetRefnum, false);            
  if(result==0)
  {
                        FldInsert(fldptr1, " Net.Libclosing", 15);
  }

  MemPtrFree (hostInfoBufP);
        
}





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

Reply via email to