Hi all,
    I have used the O'Reilly book to get NetLib running, I can send a user
name to a server get the response and then send a password back, then get
the info that I need back into the palm.  I stoped at chapter 9 though, it
got me to where I wanted to get, at least in sending text back and forth, I
do need to still figure out how to open the data socket, I haven't even
tried yet, but after what I went through to get this far, it doesn't seem
like it would be too tough.
    One thing about the book though is probably what gave me the most
trouble, it is the CR and LF at the end of what it sends, it would not work
the way the book said, so I had to substitute a '\r' and a '\n' for the Hex
codes then it worked, but more than likely since I have about 3 months
programing the palm under my belt that it was something I did wrong, but I
got it to work.
bill

----- Original Message -----
From: "Lance" <[EMAIL PROTECTED]>
Newsgroups: palm-dev-forum
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Thursday, February 28, 2002 7:22 AM
Subject: Re: Using Netlib... Code snippet to send data to server works but
reading buffer is causing problems


> Marc,
>
> Good luck finding working examples on Netlib.  My company is trying to
> decide which device to support for our mobile workforce and I am trying to
> develop a simple demo showing data exchange with a backend system with
> PocketPC and Palm.  PocketPC version was up and running in less than two
> days using SOAP (HTTP/XML combo).  It has been two weeks now and I am
still
> struggling with Netlib and haven't even thought about how to write an XML
> parser (since there doesn't seem to be any for Palm).  Going into this
> exercise I was confident we would go with Palm but I believe our
developers
> would just have too much trouble getting up to speed due to the near
> complete lack of code snippets on the internet.  I looked at the other
posts
> to your comment and personally didn't find either to be too helpful (Palm
> example doesn't actually show a working example and the O'Reilly example
> appears to use datatypes that aren't compatible with PalmOS 3.5... at
least
> not for a newbie like me).  I like the Palm devices and hope they can get
> more examples up for the corporate developer before MS takes over this
> market too (search for NetLibReceive in Yahoo netted 10 results, less than
> 40 on google, and a mere 4 on Palm's own page).
>
> Anyway... here is some code that does what you asked for but not much
> more... Basically it will successfully open a socket and send a string to
> another computer (I used a test bench found at
> http://www.vbip.com/winsock-api/listen-accept/listen-accept-01.asp to
verify
> that a connection was established and that data was recieved by the
server.
> I have also sent data back to the Palm and believe that it is arriving due
> to the number of bytes 'read' from the port.  Unfortunately, I am now
> struggling with string manipulation and haven't been able to actually see
> the data that was received.  If you crack this nut I would be happy to
hear
> from you (I would be satisfied just to see the text show up in an alert
box
> at this point).
>
> My environment consists of:
> -Windows 2000
> -Metrowerks Codewarrior 8.0 demo version
> -Palm OS Emulator
>
> As others have said, you will probably need to right click on the emulator
> face and goto Settings --> Properties and select 'Redirect Netlib calls to
> host TCP/IP'.  I believe you need to add a couple of headers shown below
and
> then a couple of global variables also shown below.  i called the
> SocketConnect method during startup with the call 'SocketConnect();' and
> display results in an alert box with 2 wildcards.  To validate that a
> connection was established I  'bound' the testbench socket to port 555 of
my
> local IP address (using IPConfig /all from the command line) and then used
> these settings with the PALM and it connected successfully.  I then
changed
> the IP address to one of our production servers, set the port to 80, and
> used the string "GET /tcpip.asp HTTP/1.0\r\n\r\n" to retrieve the
> 'tcpip.asp' test page that we made.  As I said above, I am pretty sure the
> data is actually getting to the Palm because when I change the page on the
> server the number of bytes 'read' changes.  Unfortunately my string
> manipulation skills won't let me actually view the data.
>
>
> I would be happy to hear from you if this works and if you can actually
see
> the results sent back to the client.
>
> Lance
>
>
> // Header files
> #include <PalmOS.h>
> #include <Sys_Socket.h>
> #include <NetMgr.h>
>
> // Global variables
> Err errno;
> UInt16 AppNetRefnum;
> Int32 AppNetTimeout;
>  Int16 mySockFd;
>
> static void SocketConnect()
> {
>  Int16 i;
>  UInt16 myHowMany;
>  UInt8* textP;
>  UInt16* sizeP;
>  struct sockaddr_in mySockAddr;
>
>  static Char sText [255] = "";
>
>  Char strX;
>  char last_read=0;
>  const char kLinefeed = 10;
>
>  Int16 bytesread;
>  Err myifErr;
>  Int32 plongAddress;
>  Int16 pintClientSize;
>  Err myErr;
>
>  AppNetTimeout = SysTicksPerSecond() * 10;
>
>  myErr = SysLibFind("Net.lib", &AppNetRefnum);
>  if (myErr){
>   FrmCustomAlert(1000,  "Net Library Failed to initialize", "", NULL);
>  };
>  myErr = NetLibOpen(AppNetRefnum, &myifErr);
>  if (myErr){
>   FrmCustomAlert(1000,  "Failed to open Net Library", "", NULL);
>  };
>  mySockFd = NetLibSocketOpen(AppNetRefnum, AF_INET, SOCK_STREAM, 0,
> AppNetTimeout, &errno);
>
>  plongAddress = NetLibAddrAToIN(AppNetRefnum, "127.0.0.1");        //
> <---------------------------You will need to put an IP address here
>  mySockAddr.sin_family = AF_INET;
>  mySockAddr.sin_port = 80;
>  mySockAddr.sin_addr.s_addr = plongAddress;
>
>  pintClientSize = sizeof(mySockAddr);
>  myErr = connect(mySockFd, &mySockAddr, sizeof(mySockAddr));
>      if (myErr) {
>             FrmCustomAlert(1000,  "Connection Failed", "", NULL);
>      }
>
>      myHowMany = NetLibSend(AppNetRefnum, mySockFd, &"GET /tcpip.asp
> 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(&strX,myHowMany), "");
>
>  myHowMany = NetLibReceive(AppNetRefnum, mySockFd, textP, *sizeP, 0, NULL,
> 0, AppNetTimeout, &errno);
>
>
> }
>
>
> "Marc Ouellette" <[EMAIL PROTECTED]> wrote in message
> news:78140@palm-dev-forum...
> >
> > Hi All,
> >
> > Does anyone have any quick samples on just making the connection to the
> > server with netlib. I am a real newbie at palm program and would like to
> > know the steps. All I have to do is make a connection to a sertain port
on
> a
> > server and send a strings.
> >
> > Thanks,
> > Marc
> >
> >
> >
> >
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/


-- 
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