I have c++ server and Arduino UNO client with Ethernet Shield. My problem is that the server detcect any disconnection (c# server, Android application), except the Arduino one. With no reason, I guess that the Arduino socket still run, even after the Arduino has no power supply. This is the Arduino code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 4);
EthernetClient client;
void setup()
{
Serial.begin(9600);
while (!Serial)
{
;
}
if (Ethernet.begin(mac) == 0)
{
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
Serial.println("connecting...");
if (client.connect("192.168.1.11", 1626))
{
Serial.println("connected");
}
else
{
Serial.println("connection failed");
}
}
void loop()
{
client.write("hello", strlen("hello")+1);
if (!client.connected())
{
Serial.println("connection failed");
client.stop();
return;
}
}
How can the Arduino close it's socket automatically when it has no power supply?