Cannot run arduino as web client I have ethernet shield mounted on arduino mega, I am able to run it as server but when i try to run it as client it doesnt work , most of the time it assigns itself 255.255.255.255 ip address which i get to know as i am printing from my sketch using Ethernet.localIP()  it sometimes randomly works but then it does nt establish connection with server, I have double checked there is no firewall on my router that can block arduino ethernet web client.

#include "Ethernet.h"
#include &lt;SPI.h&gt;
#include&lt;dht.h&gt;
dht DHT;

#define DHT11_PIN 8

double tempInC;
int humidity;

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
//IPAddress ip(192, 168, 1, 177);

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,1,177);

byte subnet[] = { 255, 255, 255, 0 }; //assigning subnet mask
byte gateway[] = { 192, 168, 1, 1 }; //assigning gateway

EthernetClient client;
char server[] = "192.168.1.3"; // IP Adres (or name) of server to dump data to

String data;

void setup() {
  Serial.begin(9600);

  while (!Serial) {
    ; //wait for serial port to connect. Needed for native USB port only
  }
  Ethernet.begin(mac, ip, gateway, subnet);

  Serial.print(F("connected. My IP is "));
  Serial.println(Ethernet.localIP());
  // give the Ethernet shield a second to initialize:
  delay(1000);
  data = "";
}

void loop() {
  int chk = DHT.read11(DHT11_PIN);
  delay(200);
  tempInC = DHT.temperature;
  humidity = DHT.humidity;
  Serial.print("Temp: ");
  Serial.print(tempInC);
  Serial.print(" Humidity: ");
  Serial.println(humidity);
  if (client.connect(server, 80)) {

    // Make a HTTP request:
    client.print(F("GET /arduino/add.php?temp1="));
    client.print(tempInC);
    client.print(F("&amp;hum1="));
    client.print(humidity);
    client.println(F(" HTTP/1.1"));
    client.print(F("Host: "));
    client.println(server);
    client.println(F("Connection: close"));
    client.println();

  }
  else {
    Serial.println(F("connection failed"));
  }

  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  else {
    Serial.println("Client not available");
  }
  if (client.connected()) {
    client.stop();  // DISCONNECT FROM THE SERVER
  }
  //  delay(60000); // WAIT FOR A MINUTE BEFORE SENDING AGAIN
  delay(10000);
}


Here is the output of what I get from above sketch

connected. My IP is 255.255.255.255
Temp: 26.00 Humidity: 63
connection failed
Client not available


Even when it gets correct IP assigned which I am setting up in the sketch the connection to server fails. 
I am very upset not being able to run client. Please help.
This could be an SD card SPI bus issue. 

Note that because the W5100 and SD card share the SPI bus, only one can be active at a time. If you are
using both peripherals in your program, this should be taken care of by the corresponding libraries. If
you're not using one of the peripherals in your program, however, you'll need to explicitly deselect it. To do
this with the SD card, set pin 4 as an output and write a high to it. For the W5100, set digital pin 10 as a
high output.


  Check the Arduino shield datasheet.


Changing pin mode:

pinMode(4, OUTPUT);
digitalWrite(4, HIGH);