tcp_send only works once, fails to second time.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

tcp_send only works once, fails to second time.

671 Views
kno
Contributor I
void cmd_run(void){
         send_nack("first\n");
         tcp_send_buffer;
         send_nack("EXIT\n");
         tcp_send_buffer;
         }

 

Hi

 

Here is my problem. I can send a tcp data once at each command like this,

 

void cmd_run(void){        

send_nack("first\n");        

tcp_send_buffer;      }  

 

void cmd_run1(void){

send_nack("EXIT\n");

tcp_send_buffer;        }

 

Both run and run1 are working fine, however if I try like this

 

 

void cmd_run(void){

         send_nack("first\n");

         tcp_send_buffer;

         send_nack("EXIT\n");

         tcp_send_buffer;

         }

 

 

It's not working. It freezes after display "first". You guys have any idea? Thanks in advance.

 

Here is a tcp_send_buffer. It's from the example files.

 

 

void tcp_send_buffer(void)

{

UINT32 len;

while(tcp_checksend(tcp_soch) < 0);     

for(len=0;:smileywink:

    {

net_buf[TCP_APP_OFFSET+len] = udp_tcp_buf[len];

if(udp_tcp_buf[len++] == '\n')

   break;

}

 

if(tcp_send(tcp_soch, &net_buf[TCP_APP_OFFSET], NETWORK_TX_BUFFER_SIZE - TCP_APP_OFFSET, len) == len)

   {

DEBUGOUT("TCP: bytes reply sent!\r\n");

}

else

{

    DEBUGOUT("TCP: error occured while trying to send data!\r\n");

}

}

Labels (1)
0 Kudos
1 Reply

280 Views
ThaManJD
Contributor III

I'm replying over a week after youve posted this so you've probably worked out a solution already but....

 

Is the line:

 

while(tcp_checksend(tcp_soch) < 0);

 

actually doing what you think it's doing? I assume the idea here is to see if the socket is free for another string of data to be sent.

 

With your problematic method, do an experiment and add a significant delay between your two sends that are inside the same function. If this works out ok then i would follow tcp_checksend to find out at what times that function is actually aware of whether the tcp socket is free or communicating.

 

Are you sure about the returns from tcp_checksend?

<0 "less than 0" is  busy? >= 0 or greater is free?

 

I wonder if when it "freezes" it is in fact hanging on that line. Do you have any debug module/software to set hardware breakpoints to see how far the code gets/where it hangs? Otherwise maybe you can use LEDs and light/extinguish them at certain code points to give you some indication. Or set/clear some i/o pin(s) and watch them on a scope.

 

by the way, what tcp/ip stack are you using?

 

John Dowdell

0 Kudos