Hey all.
I implemented a http server on C33.
But in a stress test the board doesn't do well.
I take the smallest sample.
#include <EthernetC33.h>
EthernetServer server(7);
void setup() {
Serial.begin(9600);
if (Ethernet.begin() == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
}
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
if (client) {
char previous_c = 0;
int sequential_newline = 0;
char buffer[1024];
int pos = 0;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (previous_c == '\r' && c == '\n')
sequential_newline++;
else if (previous_c != '\n' || c != '\r')
sequential_newline = 0;
if (sequential_newline == 2)
break;
previous_c = c;
buffer[pos++] = c;
}
}
client.write(buffer, pos );
delay(1);
// close the connection:
client.stop();
}
}
and the python code to call
import socket
server_address = ('192.168.0.103', 7) # Replace with the desired server address and port
while True:
tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_socket.connect(server_address)
data = b"POST /mode/IDLE HTTP/1.1\r\nHost: 192.168.0.103\r\nUser-Agent: python-requests/2.28.1\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n"
tcp_socket.sendall(data)
while True:
response = tcp_socket.recv(1024)
if not response:
break
print(response.decode(), end='')
tcp_socket.close()
I take a deep look on the source code too. It looks that a problem in lwip function
tcp_output that doesn't clean the recv buffer in some way.
And it's looks that is something low level because the C33 stops to respond to ping too.
Any help?