Ethernet Shield And TCP Server Problem

Hi,

I use ethernet shield sample codes which is at library samples. There is a sensor connected to Arduino Mega R3 and i send sensor results to a TCP Server software via Ethernet Shield. Everything works fine except my TCP Server software (it’s also developed by me) can’t catch “disconnect” event when i power down of Arduino Mega. TCP Server can catch disconnect event with other cleint softwares which run on windows machines.

Here is my sample code :

#include <Ethernet.h>
#include <SPI.h>

int sensorPin = A2;    
int ledPin = 13;      
int sensorValue = 0;  

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 11 };
byte server[] = { 192, 168, 1, 10 };

EthernetClient client;
void setup()
{

	Ethernet.begin(mac, ip);
	Serial.begin(9600);

	delay(1000);

	Serial.println("connecting...");
	
	if (client.connect(server, 8080)) {
		Serial.println("connected");
		pinMode(ledPin, OUTPUT);
	}
	else {
		Serial.println("connection failed");
	}
}

void loop()
{
	if (client.connected()) {
  	  digitalWrite(ledPin, HIGH);
  	  sensorValue = analogRead(sensorPin);
  	  if (sensorValue>1015){
              client.write("7");        
              while (sensorValue>1015){
                sensorValue = analogRead(sensorPin);
              }
             Serial.println(sensorValue);
              delay(400);
          }
        }
	else
	{
  	  client.stop();
          digitalWrite(ledPin, LOW);
  	  Serial.println("disconnecting.");
  	  if (client.connect(server, 8080)) {
    	    Serial.println("connected");
  	    digitalWrite(ledPin, HIGH);
  	  }
	}
}

Thanks in advance

Everything works fine except my TCP Server software (it's also developed by me) can't catch "disconnect" event when i power down of Arduino Mega.

Don't you think you should fix your TCP Server software in this case? Where is this software running? A Windows box?

Disconnect is a tcp message, not a hardware fail. When you power down the Arduino, no disconnect message is sent. The server won't know the client is down unless there is some sort of timeout to disconnect if the server doesn't hear from the client for a specified period.

pylon:

Everything works fine except my TCP Server software (it’s also developed by me) can’t catch “disconnect” event when i power down of Arduino Mega.

Don’t you think you should fix your TCP Server software in this case? Where is this software running? A Windows box?

Yes TCP Server works at a windows Server 2003 machine. And you’re right that i should do extra something at my TCP Server software

SurferTim:
Disconnect is a tcp message, not a hardware fail. When you power down the Arduino, no disconnect message is sent. The server won’t know the client is down unless there is some sort of timeout to disconnect if the server doesn’t hear from the client for a specified period.

Thanks for support. I should implant some functions (such pinging) at my TCP Server software.

Regards