I am trying to get two NanoESP32s to communicate with each other over WiFi, one is running C and the other micropython. The project can be found here. Everything works fine, with the C NanoESP32 sending code to the micropython NanoESP32 which then runs the code.
The only problem is that the C NanoESP32 doesn't receive a resonse from the micropython NanoESP32 to say the code was executed successfully or the errors found.
The code on the micropython NanoESP32 that should send the response is:
client.sendall(response.encode())
And the code on the C NanoESP which sends the code and should receive the response is:
else if (input == "send") {
if (client.connect(serverIP, serverPort)) {
String sendCode = (input == "send") ? response : Serial.readStringUntil('\n');
sendCode.trim();
Serial.println(sendCode);
// Ensure the message ends with a newline character to signal the end of transmission
client.println(sendCode + "\n"); // Append a newline character
Serial.println("Code sent to server");
// Wait for a response or timeout after a period
unsigned long startTime = millis();
while (client.connected() && millis() - startTime < 10000) { // 5-second timeout
if (client.available()) {
String serverResponse = client.readStringUntil('\n');
Serial.println("Server response: " + serverResponse);
break; // Exit loop once a response is received
}
}
if (!client.available()) {
Serial.println("No response received or connection timed out.");
}
client.stop();
Serial.println("Connection closed");
} else {
Serial.println("Connection failed");
}
blinkLed();
}
I would really appreciate some feedback on why this response is either not being sent or not being recieved.
Let's see if I can help 
when you send the response from MP, does the C code ever get in here?
if (client.available()) {
String serverResponse = client.readStringUntil('\n');
Serial.println("Server response: " + serverResponse);
break; // Exit loop once a response is received
}
If not, the issue might be on the MP side of things, which you did not post code for.
What do you get after the timeout, since the client.available() is probably not happening?
Thanks for the reply, where should I include that code. I tried placing before the "if (!client.available()) {" line but then I get the compilation error "error: break statement not within loop or switch"
that code is already in the code you have, inside the while()
I asked if you get anything from that client.available() or you just get to no response... and then connection closed
having the whole codebase, C and MicroPython could help hunt down the issue
I just get
Code sent to server
No response received or connection timed out.
Connection closed
The micropython code for executing and sending this is;
# Execute the received code
try:
print(code)
exec(code)
response = "Code executed successfully"
print (response)
except Exception as e:
response = "Error executing code: " + str(e)
# Send the response back to the first ESP32
client.sendall(response.encode())#.encode converts string to bytes so that it can be sent via .sendall
# Close the connection
client.close()
print("Client disconnected")
The whole code can be found in the link in the OP.
it could be possible that the timeout happens before the data is sent to the client of the MP server
How could I rectify that?
first of all try to extend the timeout to 20000.
it's extreme, and some sort of internal timeout might happen in-between (not sure how it works).
can you try to just send a single byte like
client.send(bytes([0xaa]))
can you post the whole MicroPython code?
I'd like to see how you instantiate the server and handle clients.
I'm a bit overwhelmed today, but I'm happy to take a look, as I think it might really be on the MP side of things.
sorry, hadn't seen the link on the word "here" 
will look into it and report back asap
found your problem, but I think you have to report it as an issue on the github repo.
this will never finish until it receives 1024 bytes of data, and the second part of the problem is that if your code is longer it will be executed "wrong" and break.
while True:
data = client.recv(1024)
print(f'data: {data}')
if not data:
break
code += data.decode()
Thanks for all your effort with this.
Is it not possible to remove the 1024 byte limit or to stuff the code to 1024 Bytes?
In order for me to understand the issue better could you give me a short micropython script that sends "Hello World" to the other NanoESP2 and a C sketch that reads the message.
I tried to intercept the \n but it's also part of the HTTP header from the request.
You'll have much better luck contacting the author of the project and ask for help 
OK, thanks for you help once again.