Here is an updated version of the code snippet I posted earlier but this
time it will display the response from the server in alert boxes 10 bytes at
a time.  From here i believe other string manipulations should be able to
make it more useful.  If you saw my earlier post you will see it was a
datatype issue that I ran into that was solved with '(Char*)&buffer[10]'...
I believe the C programmers in the world would call this 'casting' but don't
quote me.  The example below loads the 'default.htm' page from Palm's web
site (actually it is the 404 error page since they must not have
default.htm).





// Header Files
#include <PalmOS.h>
#include <Sys_Socket.h>
#include <NetMgr.h>

// Global Variables
Err errno;
UInt16 AppNetRefnum;
Int32 AppNetTimeout;
 Int16 mySockFd;

// Function
static void SocketConnect()
{
 UInt16      pintBytesTransmitted;
 Char      pcharChar;
 Err      perrError;
 Int16      pintLoop;
 struct  sockaddr_in   psockSocketAddr;

 char*  buffer[10];

     if (SysLibFind("Net.lib", &AppNetRefnum)){
        FrmCustomAlert(1000,  "Net Library Failed to initialize", "", NULL);
     }else{
  if (NetLibOpen(AppNetRefnum, &perrError)){
   FrmCustomAlert(1000,  "Failed to open Net Library", "", NULL);
  } else {
   AppNetTimeout = SysTicksPerSecond() * 10;
   mySockFd = NetLibSocketOpen(AppNetRefnum, AF_INET, SOCK_STREAM, 0,
AppNetTimeout, &errno);
   psockSocketAddr.sin_family = AF_INET
      psockSocketAddr.sin_addr.s_addr = NetLibAddrAToIN(AppNetRefnum,
"205.141.213.7");
      psockSocketAddr.sin_port = 80;

    if (connect(mySockFd, &psockSocketAddr, sizeof(psockSocketAddr))) {
              FrmCustomAlert(1000,  "Connection Failed", "", NULL);
       } else {
    pintBytesTransmitted = NetLibSend(AppNetRefnum, mySockFd, &"GET
/default.htm HTTP/1.0\r\n\r\n", strlen("GET /tcpip.asp HTTP/1.0\r\n\r\n"),
0, 0, 0, AppNetTimeout, &errno);
    FrmCustomAlert(1000,  "Sending bytes",
StrIToA(&pcharChar,pintBytesTransmitted), "");
    pintLoop = 0;
    while (pintBytesTransmitted != 0){
        pintLoop = pintLoop + 1;
        pintBytesTransmitted = NetLibReceive(AppNetRefnum, mySockFd,
&buffer[10], 10, 0, NULL, 0, AppNetTimeout, &errno);
     FrmCustomAlert(1000,  "", (Char*)&buffer[10], "");
    }
   };
 };
 };
}



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

Reply via email to