Hi,
I use NetLib receive and send with 200K files with no problem.
what kind of connection do you use ? modem, cell phone ?
Ricardo
----- Original Message -----
From: "阿謙" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Monday, October 20, 2003 11:16 PM
Subject: NetLib questions...
> Hi! I'm using CW and NetLib to develop application that sends/receives
files
> to and from a java server.
> I've come across a huge question that I've been working on to solve it for
> months. That is:
>
> 1. When receiving a file from the server, it seems impossible to receive a
> large file completly. I use for loop to re-receive the buffer that holds
the
> file on the server.
> But the connection seems unstable. For example, I want to receive a
file
> sized 73681bytes. Most of the time, when I receive 7888 bytes, then it get
> stuck. And some times I can receive the file up to 46000 bytes. Why
is
> that!? It had been bothering me for a long time..... Here is a section of
my
> code for receiving files.
>
> Boolean Receive_File()
> {
> MemPtr HTTPContent = MemPtrNew(4096);
>
> int flag = 1;
> int loop = 1;
> Boolean reconnect;
> Err Receive_File_ErrorMsg;
>
> UInt32 filesize = NULL;
>
>
> while(flag==1)
> {
> //*****************************************
> // Check and print File Size
> //*****************************************
> VFSFileSize(fileRefP, &filesize);
> char* size;
> char f[3];
> int line2=0;
> size = StrIToA(f, filesize);
> WinDrawChars("File Size:", strlen("File Size:"),40,30);
> WinDrawChars(size, strlen(size),50,40+line2);
> line2+=10;
>
> if((int)filesize == 73681)
> {
> flag =0;
> reconnect = false;
> }
>
> else
> {
> connect = NetLibReceive(libRefNum, sockfd, HTTPContent,4096,
> 0,NULL, 0, timeout, &Receive_File_ErrorMsg);
> if(connect == -1)
> {
> char* ErrorMessage;
> ErrorMessage = NetLibReceive_ErrorMsg(Receive_File_ErrorMsg);
> WinDrawChars("ERROR in NetLibReceive", strlen("ERROR in
> NetLibReceive"),50,130);
> WinDrawChars(ErrorMessage, strlen(ErrorMessage),0,140);
> MemSet(HTTPContent, 4096, 0);
> flag=1;
>
> //*****************************************
> // Check how many times
> //*****************************************
> StrIToA(LOOP, loop);
> loop++;
> WinDrawChars("loop: ", 5,70,150);
> WinDrawChars(LOOP, strlen(LOOP),100,150);
>
> if(loop>5)
> {
> flag = 0;
> reconnect = true;
> }
>
>
> }//if(connect = -1)
>
> else if(connect == 0)
> {
> WinDrawChars("Connection Closed!", strlen("Connection
> Closed!"),0,140);
> flag = 0;
> reconnect = false;
> }
> else // if there're incomming bytes
> {
>
> file_err = VFSFileWrite(fileRefP,connect,HTTPContent, NULL );
> MemSet(HTTPContent, 2048, 0);
> reconnect = false;
>
>
> }
> }//end of else
>
> }//end of while loop
> VFSFileClose(fileRefP);
> MemPtrFree(HTTPContent);
> return reconnect;
> }
>
> 2. The second problem that I come across is that when sending a file to
the
> server, it works fine while the file size is 30k. But when sending a JPEG
> file that is 86.4k, the server did receive the file, but the actual byte
> that received isn't correct. It's less than 86.4K and the tail of the file
> twisted. Can anyone please tell me what cause this happen...
>
> Here is a section of my code to send files.
>
> int line=0,flag=1, SEND_BUFFER_SIZE = 2048,sendByte = 0;
> UInt32 numBytesRead;
> Char byte[3];
> MemPtr bufP_attach = MemPtrNew(SEND_BUFFER_SIZE);
>
> while(flag==1)
> {
> VFSFileRead (fileRefP_attach, SEND_BUFFER_SIZE, bufP_attach,
> &numBytesRead);
> if(numBytesRead == 0)
> {
> flag = 0;
> break;
> }
> connect = NetLibSend(libRefNum, sockfd, bufP_attach,
> numBytesRead,0,NULL,0,timeout*2,&err );
> if(connect == -1)
> {
> flag = 0;
> WinDrawChars("ERROR in NetLibSend", strlen("ERROR in
> NetLibSend"),10,90);
> NetLibSocketClose(libRefNum, sockfd, timeout, &err);
> NetLibClose(libRefNum, 0);
> }
> MemSet(bufP_attach, SEND_BUFFER_SIZE, 0);
> StrIToA(byte, connect);
> WinDrawChars(byte, strlen(byte),100,line+=8);
>
> }
>
> WinDrawChars("File has been sent!",strlen("File has been
sent!"),10,90);
> VFSFileClose(fileRefP_attach);
> free(bufP_attach);
>
>
> Angela Chang
>
>
>
> ==========================================================
> ?W-E|nA§|U?vAE !!
> http://edm-prg.epaper.com.tw/click.php?ad_code=29350
> ==========================================================
> PChome¥a?I~~c¯oO?N?N|3 \*^o^*//
> http://love.pchome.com.tw/
> ==========================================================
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/