Author Topic: About long TCP messages ...  (Read 11972 times)


OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #1 on: March 24, 2007, 02:37:14 AM »
I have no problems at all to send short messages (< 970 bytes!). And i use your examples, but all examples send few bytes.... And as i see examples of version 3.05 and 3.06 (about TCP)are the same of version 3.04! So my problem it's not about how implement it, otherwise i must have problems also in version in 3.04....

This is the code that in version 3.04 is working: it reads from FRAM blocks of TMP_BUFFER_SIZE = 128 bytes and it send to TCP... 
FRAM_BUFFER_SIZE = 1024

Of course before there is all the portion of code that listen and so on... This is not the aim of the question.
 
Code: [Select]
            else if ((((BYTE)(tcpRxBuf[rxAmount-1]))>=0xF8)&&  // Read FRAM circular buffers
                     (((BYTE)(tcpRxBuf[rxAmount-1]))<=0xFF))
             {
              // bufferNum pointer
              ChSel = (BYTE)((tcpRxBuf[rxAmount-1])-0xF8);
              // Split Send Buffer Size in group of TMP_BUFFER_SIZE bytes (limit of local var)
              #define LOOP_CNT    FRAM_BUFFER_SIZE/TMP_BUFFER_SIZE
              for (auxLoop=0;auxLoop<(LOOP_CNT);auxLoop++)
               {
                // Read Group of TMP_BUFFER_SIZE bytes
                FRAM_ReadArr ((ChSel*FRAM_BUFFER_SIZE)+(auxLoop*TMP_BUFFER_SIZE), &(auxData[0]),TMP_BUFFER_SIZE);
                for (auxIdx=0;auxIdx<TMP_BUFFER_SIZE;auxIdx++)
                {
                 //Send Group of TMP_BUFFER_SIZE bytes
                 TCPPut(TCPuSocket, auxData[auxIdx]);
                }
               }
              TCPFlush(TCPuSocket);
             }

In version 3.04 i receive PERFECTLY 1024 bytes. In version 3.06 i receive only 970.
What should i do to fix this problem?
« Last Edit: March 24, 2007, 02:41:46 AM by OmarZ »

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #2 on: March 27, 2007, 12:24:18 PM »
Anybody here can tell me what should i do to fix this problem???

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #3 on: April 01, 2007, 01:36:55 AM »
ok.....i think i will still use 3.04, but i'm not happy about this....

modtro2

  • Administrator
  • Hero Member
  • *****
  • Posts: 564
    • View Profile
Re: About long TCP messages ...
« Reply #4 on: April 03, 2007, 02:05:14 PM »
Quote
The TCP functions have to be working for longer then 970 byte messages, seeing that HTTP uses the TCP module, and many of the pages are much longer then 970 bytes. For example, the JavaScript source code is a couple of kbytes long, and is sent fine in all versions via TCP. I guess you must be using the TCP functions incorrectly. Could you maybe create a simple example program showing how you sent your TCP message, and post it. Remember that after doing a flush, you must wait until the TCP message has been sent, before sending the next message. Maybe you can modify one of the TCP examples given at http://www.modtronix.com/products/sbc65ec/websrvr65_v305/examples.html

Sorry for later responce. Thanks for your code! Seeing that HTTP that sends much larger messages is still working, this problem has had quite low priority. I will however try your code and see if I can find why it does not work for that code! It might just take a while :-(

Jean-Marc DELPRAT

  • Sr. Member
  • ****
  • Posts: 36
    • View Profile
Re: About long TCP messages ...
« Reply #5 on: April 11, 2007, 05:05:53 AM »
Omar,

Im not sure, but a quick glance to your code shows that you assume that the TcpPut function can accept TMP_BUFFER_SIZE bytes, that's all.

I think the correct way is to let TcpPut decide how many bytes it can accept and prior to call TcpPut you MUST call TCPIsPutReady to check if TcpPut is ready or not.  (for each single byte you want to send !!!)

If TCPIsPutReady is FALSE it shows that TcpPut is busy sending a packet, your routine must do nothing else but go on checking TCPIsPutReady (while calling the stack of course) and may be also TCPIsConnected to avoid waiting forever if the connection is closed.

When TcpPut will have sent some old data it will accept again your new data and therefore you can send an unlimited amount of data, but in several packets.
 
hope this helps,
jm

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #6 on: April 11, 2007, 11:35:22 AM »
....so why using firmware version 3.04 is working well?

I try also to made as simple as possible:
Code: [Select]
              int auxIdx;

              for (auxIdx=0;auxIdx<(1024);auxIdx++)
               {
                 TCPPut(TCPuSocket, 0xBB);
               }
               TCPFlush(TCPuSocket);
and the result is the same:
version 3.04 OK        - 1024 bytes
version 3.05 NOT OK -  970 bytes only
version 3.06 NOT OK -  970 bytes only

So, how can i fix the problem? And why with old version it works?

And also why MUST i use TCPIsPutReady to check if TcpPut is ready or not and in all tcp stack developed by modtronix this is not done?
« Last Edit: April 11, 2007, 12:34:30 PM by OmarZ »

Jean-Marc DELPRAT

  • Sr. Member
  • ****
  • Posts: 36
    • View Profile
Re: About long TCP messages ...
« Reply #7 on: April 12, 2007, 04:00:17 AM »
I cannot answer why 3.04 has a larger buffer size than 3.05, may be to save some ram ? But suppose that tomorrow you have to send 1200 bytes or more, how you'll do ?

If you look at the ftp or http sources, you'll see how it is done, and it is very easy in fact, if the stack is busy sending the buffer, just do nothing and when the stack has sent the buffer it will accept your data again until the end of data or buffer full again...

I hope that the application at the other end will accept receiving the data in 2 packets, but if correctly programmed it shouldn't.

Best regards,
JM

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #8 on: April 12, 2007, 10:11:21 AM »
so, how ???? Please write how? In this way?? STILL DO NOT WORK, THE BOARD CRASH!!!
Code: [Select]
                 
              int auxIdx;
              //Send 8kb
              for (auxIdx=0;auxIdx<(8192);auxIdx++)
               {
                  while (!TCPPut(TCPuSocket, 0xBB)) {
                   if (!TCPIsPutReady(TCPuSocket)){
                    StackTask();// If you don't call StackTask, TCPisPutReady will never become TRUE
                    if (!TCPIsConnected(TCPuSocket)){
                       break;// Connection dropped...Error
                    }
               }
               TCPFlush(TCPuSocket);



actually in version 3.04 i'm not only able to send 1kb but also 2kb , 4kb and 8kb without any trick and any error!!!

Code: [Select]
             
              int auxIdx;
              //Send 8kb
              for (auxIdx=0;auxIdx<(8192);auxIdx++)
               {
                 TCPPut(TCPuSocket, 0xBB);
               }
               TCPFlush(TCPuSocket);

version 3.04 OK        - 8192 bytes
version 3.05 NOT OK -  970 bytes only
version 3.06 NOT OK -  970 bytes only
« Last Edit: April 12, 2007, 10:17:08 AM by OmarZ »

Jean-Marc DELPRAT

  • Sr. Member
  • ****
  • Posts: 36
    • View Profile
Re: About long TCP messages ...
« Reply #9 on: April 12, 2007, 01:02:21 PM »
This is strange....

but are you really sure that 3.04 sends all 8192 bytes ?

I'll check that next time i work on one of my boards....  Please allow me a few days...

best regards,
jm



OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #10 on: April 12, 2007, 01:37:35 PM »
yes!!! try if you do not believe me with thi simple for cycle!!!

Code: [Select]
             
              int auxIdx;
              //Send 8kb
              for (auxIdx=0;auxIdx<(8192);auxIdx++)
               {
                 TCPPut(TCPuSocket, 0xBB);
               }
               TCPFlush(TCPuSocket);

If you analyze tcp messages with Ethereal you will found that AUTOMATICALLY it will split message in 8 messages of 970 bytes + 1 of 432 bytes = 8192 bytes. In attach you can see Ethereal capture (check from Frame 23) .
Frame 23 = 970 bytes
Frame 24 = 970 bytes
and so on...

 So it works without any other software implementation!
« Last Edit: April 12, 2007, 01:42:22 PM by OmarZ »

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #11 on: April 16, 2007, 01:45:28 PM »
And what about this? If i tell you that it works PERFECTLY, do you believe or not! 24kb of data!!!

I think something really good is lost from 3.04 to 3.05 and 3.06.....I hope somebody will fix this....Actually i really have no time.

Code: [Select]
              //Send 24kb of data
              for (auxIdx=0;auxIdx<(1024*24);auxIdx++)
               {
                 TCPPut(TCPuSocket, 0xAA);
               }
               TCPFlush(TCPuSocket);
« Last Edit: April 16, 2007, 01:47:15 PM by OmarZ »

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #12 on: April 16, 2007, 01:51:38 PM »
Quote
The TCP functions have to be working for longer then 970 byte messages, seeing that HTTP uses the TCP module, and many of the pages are much longer then 970 bytes. For example, the JavaScript source code is a couple of kbytes long, and is sent fine in all versions via TCP. I guess you must be using the TCP functions incorrectly. Could you maybe create a simple example program showing how you sent your TCP message, and post it. Remember that after doing a flush, you must wait until the TCP message has been sent, before sending the next message. Maybe you can modify one of the TCP examples given at http://www.modtronix.com/products/sbc65ec/websrvr65_v305/examples.html

Sorry for later responce. Thanks for your code! Seeing that HTTP that sends much larger messages is still working, this problem has had quite low priority. I will however try your code and see if I can find why it does not work for that code! It might just take a while :-(

When you have time, try this and see the difference between version 3.04 and later.
Code: [Select]
             
              //Send 24kb of data
              for (auxIdx=0;auxIdx<(1024*24);auxIdx++)
               {
                 TCPPut(TCPuSocket, 0xAA);
               }
               TCPFlush(TCPuSocket);

Jean-Marc DELPRAT

  • Sr. Member
  • ****
  • Posts: 36
    • View Profile
Re: About long TCP messages ...
« Reply #13 on: April 16, 2007, 10:35:32 PM »
Hello Omar,

I did not had the opportunity to made some testing, but i had an idea:

The stack has 2 modes:
One that wait for an ack after sending an other TCP packet. (and is able to make retries)
Another that do NOT wait for an ack and send the following(s) packets.

may be the two stack versions you are comparing are not configured the same ? And if the stack wait for an ack, you must not send another packet before ack is received (stack ready).

this is configured in projdefs.h

JM


/*
 * Comment following line if StackTsk should wait for acknowledgement
 * from remote host before transmitting another packet.
 * Commenting following line may reduce throughput.
 */
//#define TCP_NO_WAIT_FOR_ACK


OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #14 on: April 17, 2007, 11:55:49 AM »
this is a good suggestion. I will check immediately