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

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #15 on: April 17, 2007, 12:26:12 PM »
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


3.04 has defined TCP_NO_WAIT_FOR_ACK in projdefs.h

I enable it also in 3.06. Result: NOT OK.

Here some Ethereal screenshots about simple TCP conection test (sends AliveMessage,SBC time and 1kb of data).
1) 3.04 - with TCP_NO_WAIT_FOR_ACK defined -> perfect and clean
2) 3.06 - with TCP_NO_WAIT_FOR_ACK not defined (modtronix default) ->some errors, short messages received properly but limited at 970 bytes
3) 3.06 - with TCP_NO_WAIT_FOR_ACK defined -> a lot of errors and also short messages not received properly


« Last Edit: April 17, 2007, 12:27:59 PM by OmarZ »

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #16 on: April 20, 2007, 05:11:39 PM »
Today i test new SBC65EC V3.06 Release Candidate 1 and still i have the same problem:
i try to play with these defines that are enable on 3.04.
#define TCP_NO_WAIT_FOR_ACK
#define STACK_CLIENT_MODE

I found the same problems i told previously: short messages ok. Messagese > 970 not ok (trunc at 970)

Note: if i enable TCP_NO_WAIT_FOR_ACK it looks very instable (sometimes i receive 970, other 58, other 44 ....)

modtro2

  • Administrator
  • Hero Member
  • *****
  • Posts: 564
    • View Profile
Re: About long TCP messages ...
« Reply #17 on: April 22, 2007, 07:48:37 PM »
Hello Omar

You must be using the TCP functions wrong. I just tested the "main_tcp4" example program with the latest stack, and it works fine sending a file of a couple of KB. Please have a look at this example to see how to use the TCP functions. You can download the examples from the SBC65EC product page, or from here:
http://www.modtronix.com/soft/mxmctcpip/examples

Remember that each time before calling the TCPPut() function, you have to call the TCPIsPutReady() function. See the sendFileToTcpServer() function in the tcputils.c file for an example how to use it. When sending a long file, each time you call the TCPPut() function, a byte will be added to the TCP socket's transmit buffer. This byte is NOT transmitted until:
  • The transmit buffer is full
  • You call TCPFlush()

If the transmit buffer fills up, you have to repetitively call StackTask() until the TCPIsPutReady() returns true again. Only once it returns true, it means that the contents of the transmit buffer has been transmitted. This is all done in the sendFileToTcpServer() function. I recommend you take this function, and modify it for sending your array of data.
« Last Edit: July 11, 2007, 04:49:10 PM by modtro2 »

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: About long TCP messages ...
« Reply #18 on: April 23, 2007, 09:59:47 AM »
OK.
I made some tests and somehow it works...

Code: [Select]
              //Send 24kb of data
             
              for (auxIdx=0;auxIdx<(1024*24);auxIdx++)
               {
                while(!TCPIsPutReady(TCPuSocket))
                 StackTask();
                TCPPut(TCPuSocket, (BYTE)(auxIdx & 0x00FF));
               }
               TCPFlush(TCPuSocket);

In src\projdefs.h i enabled this define to improve TCP speed:
//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

About example of 24kb:NOT ENABLED(default): 4890ms; ENABLED: 985ms


At the end, no changes from PIC side, but i must change delphi application i developed to merge 970bytes length messages. I made a quick test and it works.
Code: [Select]
    //dirty code: only for quick test
    kk := ((1024*24)div 970);
    for i:=0 to kk-1 do
     recLen := recLen + FClient.ReceiveBuf(rxbuffer[970*i],970);
    remLen := (1024*24)-(970*kk);
    if remLen>0 then
     recLen := recLen + FClient.ReceiveBuf(rxbuffer[970*kk],remLen);

Thank you very much for the help!
« Last Edit: April 23, 2007, 12:55:30 PM by OmarZ »