Ethernet transfer stops

Hi,
I'm trying to transmit multipart http post through Ethernet from a browser and it fails consistently at point of between about 2045~2085 byte of a (any) file.
The receiving test code is:

   while(client.available())
    {
      c = client.read();
      Serial.print(c);
    if(client.available()==false){delay(1000);Serial.println("no client");}
    }//while

The html is:

<html><body>Upload file:<FORM NAME="InputForm" ACTION="load" METHOD="POST" enctype="multipart/form-data">
<input type="file" name="filename">
<input type="submit" value="Upload">
</FORM>File name is 12 character MAX!

<a href="/browse">Browse files</a></body></html>

The Serial output is:

POST /load HTTP/1.1
Host: 192.168.1.106
User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Referer: http://192.168.1.106/browse
Content-Type: multipart/form-data; boundary=---------------------------4827543632391
Content-Length: 4494

-----------------------------4827543632391
Content-Disposition: form-data; name="filename"; filename="ring.txt"
Content-Type: text/plain

%
G21
G90
G01 X0.000 Y0.000 Z0.036
G01 X0.054 Y0.120
G01 Z0.015
G01 X0.055 Y0.114
G01 X0.056 Y0.107
G01 X0.057 Y0.101
G01 X0.059 Y0.095
G01 X0.062 Y0.089
G01 X0.065 Y0.083
G01 X0.069 Y0.078
G01 X0.074 Y0.074
G01 X0.078 Y0.069
G01 X0.083 Y0.065
G01 X0.089 Y0.062
G01 X0.095 Y0.059
G01 X0.101 Y0.057
G01 X0.107 Y0.056
G01 X0.114 Y0.055
G01 X0.120 Y0.054
G01 X0.126 Y0.055
G01 X0.133 Y0.056
G01 X0.139 Y0.057
G01 X0.145 Y0.059
G01 X0.151 Y0.062
G01 X0.157 Y0.065
G01 X0.162 Y0.069
G01 X0.166 Y0.074
G01 X0.171 Y0.078
G01 X0.175 Y0.083
G01 X0.178 Y0.089
G01 X0.181 Y0.095
G01 X0.183 Y0.101
G01 X0.184 Y0.107
G01 X0.185 Y0.114
G01 X0.186 Y0.120
G01 X0.185 Y0.126
G01 X0.184 Y0.133
G01 X0.183 Y0.139
G01 X0.181 Y0.145
G01 X0.178 Y0.151
G01 X0.175 Y0.157
G01 X0.171 Y0.162
G01 X0.166 Y0.166
G01 X0.162 Y0.171
G01 X0.157 Y0.175
G01 X0.151 Y0.178
G01 X0.145 Y0.181
G01 X0.139 Y0.183
G01 X0.133 Y0.184
G01 X0.126 Y0.185
G01 X0.120 Y0.186
G01 X0.114 Y0.185
G01 X0.107 Y0.184
G01 X0.101 Y0.183
G01 X0.095 Y0.181
G01 X0.089 Y0.178
G01 X0.083 Y0.175
G01 X0.078 Y0.171
G01 X0.074 Y0.166
G01 X0.069 Y0.162
G01 X0.065 Y0.157
G01 X0.062 Y0.151
G01 X0.059 Y0.145
G01 X0.057 Y0.139
G01 X0.056 Y0.133
G01 X0.055 Y0.126
G01 X0.054 Y0.120
G01 X0.015
G01 Z0.034
G01 X0.054 Z0.035
G01 Z0.015
G01 X0.059 Y0.099
G01 Y0.141
G01 X0.065 Y0.155
G01 X0.066 Y0.085
G01 X0.073 Y0.076
G01 X0.072 Y0.162
G01 X0.079 Y0.169
G01 X0.081 Y0.070
G01 X0.089 Y0.064
G01 X0.087 Y0.175
G01 X0.095 Y0.179
G01 X0.097 Y0.061
G01 X0.104 Y0.058
G01 X0.103 Y0.181
G01 X0.110 Y0.184
G01 X0.111 Y0.056
G01 X0.119
G01 X0.117 Y0.184
G01 X0.125
G01 X0.126 Y0.056
G01 X0.134 Y0.057
G01 X0.132 Y0.183
G01 X0.140 Y0.181
G01 X0.141 Y0.060
G01 X0.149 Y0.064
G01 X0.148 Y0.178
G01 X0.156 Y0.173
G01 X0.157 Y0.068
G01 X0.165 Y0.075
G01 X0.164 Y0.167
G01 X0.170 Y0.160
G01 X0.172 Y0.082
G01 X0.178 Y0.091
G01 X0.176 Y0.153
G01 X0.182 Y0.099
G01 X0.185 Y0.114
G01 X0.181 Y0.145
G01 X0.217 Y0.160
G01 Z0.040
G01 X0.118 Y0.205
G01 Z0.000
G01 Z0.038
G01 X0.122 Y0.036
G01 Z0.000
G01 Z0.036
G01 X0.110 Y0.120 Z0.035
G0no client

The WireShark says (though I have no idea what it means):

No.     Time           Source                Destination           Protocol Length Info
      1 0.000000000    Giga-Byt_42:ae:33     Broadcast             ARP      42     Who has 192.168.1.106?  Tell 192.168.1.100
      2 0.000165000    192.168.1.106         Giga-Byt_42:ae:33     ARP      60     192.168.1.106 is at de:ad:be:ef:fe:ed
      3 0.000173000    192.168.1.100         192.168.1.106         TCP      62     54537 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 SACK_PERM=1
      4 0.000320000    192.168.1.106         192.168.1.100         TCP      60     http > 54537 [SYN, ACK] Seq=0 Ack=1 Win=2048 Len=0 MSS=1460
      5 0.000353000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=1 Ack=1 Win=64240 Len=0
      6 0.000554000    192.168.1.100         192.168.1.106         TCP      1514   [TCP segment of a reassembled PDU]
      7 0.203088000    192.168.1.106         192.168.1.100         TCP      60     http > 54537 [ACK] Seq=1 Ack=1461 Win=1297 Len=0
      8 0.203129000    192.168.1.100         192.168.1.106         TCP      1351   [TCP Window Full] [TCP segment of a reassembled PDU]
      9 0.405640000    192.168.1.106         192.168.1.100         TCP      60     http > 54537 [ACK] Seq=1 Ack=2758 Win=712 Len=0
     10 1.786733000    192.168.1.106         192.168.1.100         TCP      95     [TCP segment of a reassembled PDU]
     11 1.786787000    192.168.1.100         192.168.1.106         TCP      1514   [TCP segment of a reassembled PDU]
     12 1.786916000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     13 1.787122000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     14 1.787177000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=4218 Ack=44 Win=64197 Len=0
     15 1.788546000    192.168.1.106         192.168.1.100         TCP      159    [TCP segment of a reassembled PDU]
     16 1.788720000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     17 1.788732000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=4218 Ack=150 Win=64091 Len=0
     18 1.788888000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     19 1.789512000    192.168.1.106         192.168.1.100         TCP      89     [TCP segment of a reassembled PDU]
     20 1.789526000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=4218 Ack=186 Win=64055 Len=0
     21 1.789681000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     22 1.789889000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     23 1.789901000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=4218 Ack=188 Win=64053 Len=0
     24 1.790501000    192.168.1.106         192.168.1.100         TCP      90     [TCP segment of a reassembled PDU]
     25 1.790688000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     26 1.790700000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=4218 Ack=225 Win=64016 Len=0
     27 1.790847000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     28 1.791541000    192.168.1.106         192.168.1.100         TCP      95     [TCP segment of a reassembled PDU]
     29 1.791558000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=4218 Ack=267 Win=63974 Len=0
     30 1.791706000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     31 1.791917000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     32 1.791933000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=4218 Ack=269 Win=63972 Len=0
     33 1.792670000    192.168.1.106         192.168.1.100         TCP      102    [TCP segment of a reassembled PDU]
     34 1.792855000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     35 1.792870000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=4218 Ack=318 Win=63923 Len=0
     36 1.793019000    192.168.1.106         192.168.1.100         TCP      60     [TCP segment of a reassembled PDU]
     37 1.794109000    192.168.1.106         192.168.1.100         HTTP     60     HTTP/1.1 200 OK  (text/html)
     38 1.794133000    192.168.1.100         192.168.1.106         TCP      54     54537 > http [ACK] Seq=4218 Ack=320 Win=63922 Len=0
     39 1.996561000    192.168.1.106         192.168.1.100         TCP      60     [TCP Dup ACK 37#1] http > 54537 [ACK] Seq=320 Ack=4218 Win=588 Len=0
     40 2.400983000    192.168.1.106         192.168.1.100         TCP      60     [TCP Dup ACK 37#2] http > 54537 [ACK] Seq=320 Ack=4218 Win=588 Len=0
     41 6.770157000    192.168.1.100         192.168.1.106         TCP      642    [TCP Window Full] [TCP segment of a reassembled PDU]
     42 6.770317000    192.168.1.106         192.168.1.100         TCP      60     http > 54537 [RST] Seq=320 Win=0 Len=0

Am I doing anything obviously wrong or should I check the network? Unfortunately the project isn't mobile. The Network is: a router for internet, computer, Ethernet shield all interconnected through a switch.

If you look at the HTTP TCP packet decodes in WireShark you will be able to see the HTTP text sent from the browser. It'll come split in several packets so you'll need to mentally reassemble these to see the whole HTTP stream. Does the content match what you're expecting the browser to send?

The serial trace you provided shows that the HTTP stream has been cut off before it was complete, but at the moment we can't see whether the whole stream was sent (implying that it might be a buffer overflow type of problem within the Arduino) or something that interrupted the TCP connection.

Usually there is a while(client.connected()) loop around the while(client.available()) loop to handle such stuff. You stop reading if for one moment there is not material in the buffer. To handle this situation correctly you have to parse the request, get the content length out and read till you got the number of bytes from the client (or a timeout occurs).

You should wait for all the packets. The server will close the connection on its end when it is finished sending packets. Maybe some aren't being read? I use this:

// send the request, then wait for disconnect from server
while(client.connected() 
{
   // read another packet
   while(client.available())
    {
      c = client.read();
      Serial.print(c);
    }
}
// close this end after the server closes its end
client.stop();

Works for me.

@pylon: You posted that as I tried to post this. :slight_smile:

PeterH:
If you look at the HTTP TCP packet decodes in WireShark you will be able to see the HTTP text sent from the browser. It'll come split in several packets so you'll need to mentally reassemble these to see the whole HTTP stream. Does the content match what you're expecting the browser to send?

The serial trace you provided shows that the HTTP stream has been cut off before it was complete, but at the moment we can't see whether the whole stream was sent (implying that it might be a buffer overflow type of problem within the Arduino) or something that interrupted the TCP connection.

Thanks.
@line 6 the browser transmission begins;
@line 8 browser continues to the point of failure (last character = last character of serial print);
@line 10 Arduino begins sending a reply (while loop have ended).
@line 11 browser resumes from where have left to some point;
@line 41 browser continues almost to the end of file but a couple of lines are still missing.

pylon:
Usually there is a while(client.connected()) loop around the while(client.available()) loop to handle such stuff. You stop reading if for one moment there is not material in the buffer. To handle this situation correctly you have to parse the request, get the content length out and read till you got the number of bytes from the client (or a timeout occurs).

Thanks, looking at what I just wrote it seems to be the case.

Solved!
It was simple as that :smiley:
Thanks a lot - by myself I'd find a solution only by tomorrow when I'd go with another board trying all the examples :slight_smile: