[En-Nut-Discussion] Missing [SYN, ACK] packets when NutTcpConnect() attempts to connect to a .NET TcpListener socket server

Alain M. alainm at pobox.com
Fri Nov 9 16:32:33 CET 2007


Your description of how to reproduce the problem, if I understood 
correctly, could be an ARP problem. Could be that the "gratuitiuous ARP" 
implementation could solve that.

a little explanation: whenever someone changes his own IP settings, he 
broadcasts a single packet called "gratuitiuous ARP" so that everyone 
else knows about it...

please comment,
Alain

Erik Lindstein escreveu:
> I have a Ethernut 2.0 (ethernut-4.2.1) board connected to a PC thru ethernet.
> In the ethernut i have client thread that handles some dataexchange
> with the PC(running a pretty simple .NET TcpListener TCP socket server
> on WinXP)
> 
> The ethernut thread is supposed to connect, exchange some data(a
> couple of xml formatted lines), read back a command from the PC,
> disconnect and wait 300ms then start all over again.
> 
> For most of the time this works fine but sometimes(for some reason)
> the systems just don't want to start exchange data.
> 
> If i analyze the trafic with wireshark i can se that the ethernut
> board sends [SYN] packets but the PC doesn't respond with anything.
> I don´t have any knowledge about how the low level TCP communication
> work's but i can se that when the communication works the PC sends
> [SYN, ACK]
> after ethernut sends [SYN].
> 
> When the communication isn't working the ethernut sends a couple of
> [SYN] then after a while the PC starts responding with [SYN, ACK] and
> the communication
> starts working again.
> While this ethernut client dossnt get any response from the PC the PC
> might still at the same time communicate with 3-4 other clients
> successfully.
> So its usually not all the connecting clients that get the silent
> treatment just a couple of them.
> 
> The best way to get this problem is to have the PC software running
> with connected clients and restart the clients.
> If i let the ethernut clients bootup then start trying to connect a
> couple of times and then start the PC software the problems usully
> dossnt show.
> 
> But when the communication is up and running it work's fine(for days)
> Its just the first connecting moment that sometimes doesn't come thru.
> I'm not sure who to blame, ethernut or the PC.
> I wrote a simple tcpclient in .NET that connects to the server and it
> looks like that one work's fine but still this problem doesn't show it
> self all the time.
> 
> Perhaps someone in the list have some ideas on how to fix this or at
> least sort out how to blame ;-)
> 
> Bellow is some data from wireshark ( Ethernut IP = 192.168.0.60, PC =
> 192.168.0.115 )
> ------------------------------------------------------------------------
> No.     Time        Source                Destination           Protocol Info
>      1 0.000000    192.168.0.60          192.168.0.115         TCP
>  4149 > 9050 [SYN] Seq=0 Len=0 MSS=536
> No.     Time        Source                Destination           Protocol Info
>      2 0.000018    192.168.0.115         192.168.0.60          TCP
>  9050 > 4149 [RST, ACK] Seq=0 Ack=1 Win=0 Len=0
> No.     Time        Source                Destination           Protocol Info
>      3 8.491477    192.168.0.60          192.168.0.115         TCP
>  4097 > 9050 [SYN] Seq=0 Len=0 MSS=536
> No.     Time        Source                Destination           Protocol Info
>      4 8.491514    192.168.0.115         192.168.0.60          TCP
>  9050 > 4097 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460
> No.     Time        Source                Destination           Protocol Info
>      5 8.492851    192.168.0.60          192.168.0.115         TCP
>  4097 > 9050 [RST] Seq=1 Len=0
> ( Here i reset the ethernut client )
> 
> ( Here the communication isn't working )
> No.     Time        Source                Destination           Protocol Info
>      6 13.408382   192.168.0.60          192.168.0.115         TCP
>  4098 > 9050 [SYN] Seq=0 Len=0 MSS=536
> No.     Time        Source                Destination           Protocol Info
>      7 14.580253   192.168.0.60          192.168.0.115         TCP
>  4098 > 9050 [SYN] Seq=0 Len=0 MSS=536
> No.     Time        Source                Destination           Protocol Info
>      8 15.758478   192.168.0.60          192.168.0.115         TCP
>  4098 > 9050 [SYN] Seq=0 Len=0 MSS=536
> No.     Time        Source                Destination           Protocol Info
>      9 16.936782   192.168.0.60          192.168.0.115         TCP
>  4098 > 9050 [SYN] Seq=0 Len=0 MSS=536
> No.     Time        Source                Destination           Protocol Info
>     10 18.115065   192.168.0.60          192.168.0.115         TCP
>  4098 > 9050 [SYN] Seq=0 Len=0 MSS=536
> No.     Time        Source                Destination           Protocol Info
>     11 18.115084   192.168.0.115         192.168.0.60          TCP
>  9050 > 4098 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460
> No.     Time        Source                Destination           Protocol Info
>     12 18.117012   192.168.0.60          192.168.0.115         TCP
>  4098 > 9050 [ACK] Seq=1 Ack=1 Win=3216 Len=0
> 
> ( Here its up and running again )
> No.     Time        Source                Destination           Protocol Info
>     13 18.121677   192.168.0.60          192.168.0.115         TCP
>  4098 > 9050 [PSH, ACK] Seq=1 Ack=1 Win=3216 Len=401
> No.     Time        Source                Destination           Protocol Info
>     14 18.121805   192.168.0.115         192.168.0.60          TCP
>  9050 > 4098 [PSH, ACK] Seq=1 Ack=402 Win=65134 [TCP CHECKSUM
> INCORRECT] Len=14
> ------------------------------------------------------------------------
> 
> 
> The ethernut tcpclient thread ( Some code arent included but i think
> it should be enough )
> ------------------------------------------------------------------------
> THREAD(InetdThread, arg)
> {
>        TCPSOCKET *sock;
>        FILE *stream;
>        u_long rip = inet_addr(TCPSERVERADDR);
>        uint8_t *start;
>        uint8_t cmd[20], value[20];
>        u_long tmo = TCP_TIMEOUT;
>        uint32_t exchange_timeout = TCP_CLIENT_NO_CONNECTION_TIMEOUT;
>        uint8_t buffer[40];
>        int socket_error = 0;
> 
>        for (;;)
>        {
>                if ((sock = NutTcpCreateSocket()) != 0)
>                {
>                        NutTcpSetSockOpt(sock, SO_RCVTIMEO, &tmo, sizeof(tmo));
>                        NutTcpSetSockOpt(sock, SO_SNDTIMEO, &tmo, sizeof(tmo));
>                        if(NutTcpConnect(sock, rip, TCPSERVERPORT) == 0)
>                        {
>                                stream = _fdopen((int) ((uptr_t) sock), "r+b");
>                                if(stream != 0)
>                                {
>                                        fprintf_P(stream, info_P, INFO_P_ARGS);
>                                        fflush(stream);
> 
>                      fgets(exchange_data_buff,
> sizeof(exchange_data_buff), stream);
> 
>                      if((start = strchr(exchange_data_buff, '\r')) !=
> 0) *start = 0;
>                  if((start = strchr(exchange_data_buff, '\n')) != 0) *start = 0;
>                                        if((start =
> strchr(exchange_data_buff, ':')) != 0)
>                                        {
> 
> strlcpy(cmd,exchange_data_buff, (start+1-exchange_data_buff));
>                                                start++;
>                                                strcpy(value,start);
>                                                //
>                                                if(strncmp(cmd, "cmd",
> sizeof(cmd)) == 0)
>                                                {
>                                                if(strncmp(value,
> "wdtreset", sizeof(cmd)) == 0)
>                                            {
>                                        if(status & (1UL<<WDT_ENABLE))
>                                        {
>                                                wdt_reset();
>                                        }
>                                                                else
>                                                                {
> 
> wdt_reset();
> 
> wdt_enable(WDTO_2S);
>                                          status |= (1UL<<WDT_ENABLE);
>                                        }
>                                          }
>                                                }
>                                                exchange_timeout =
> TCP_CLIENT_CONNECTION_RATE;
>                                        }
>                                        else
>                                        {
>                                                socket_error = NutTcpError(sock);
>                                                sprintf(buffer,"Connect
> error\nCode: %d", socket_error);
> 
> lcd_menu_write_text_to_display(buffer, 3000);
>                                                exchange_timeout =
> TCP_CLIENT_NO_CONNECTION_TIMEOUT;
>                                        }
>                                }
>                                fclose(stream);
>                                NutTcpCloseSocket(sock);
>                        }
>                }
>                else
>                {
>                        exchange_timeout = TCP_CLIENT_NO_CONNECTION_TIMEOUT;
>                }
>                NutSleep(exchange_timeout);
>        }
> }
> ---------------------------------------------------
> 
> 
> /Erik
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
> 
> 



More information about the En-Nut-Discussion mailing list