Wifi Shield - client.connect not working - connection failed

I am trying to use the client.connect method to connect to external website with my Wifi Shield. I get an IP address and I am connected to the wireless network, but the client.connect command always returns false. When I run the following code I get the following in the serial monitor:

Attempting to connect to SSID: xxxxxxxxxxxxxxxxxxxxxxxxxx
SSID: xxxxxxxxxxxxxxxxxxxxxxxxxx
IP Address: 192.168.0.177

signal strength (RSSI):-38 dBm
IP Address: 192.168.0.177

Firmware version: 1.1.0
connection failed
connection failed
connection failed
connection failed
connection failed
connection failed
connection failed
connection failed
connection failed

Any help would be appreciated.

#include <SPI.h>
#include <WiFi.h>

// the IP address for the shield:
IPAddress ip(192, 168, 0, 177);
//Serial.begin(9600);

char ssid = “xxxxxxxxxxxxxxxxxxxxxxxx”; // your network SSID (name)
char pass = “xxxxxxxxxxxxxxxxxxxx”; // your network password (use for WPA, or use as key for WEP)

char server = “www.arduino.cc”;
//IPAddress server(64,131,82,241);

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds

int status = WL_IDLE_STATUS;

// Initialize the Ethernet client library
WiFiClient client;

void setup()
{
// Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(“WiFi shield not present”);
while(true); // don’t continue
}

WiFi.config(ip);

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
WiFi.config(ip);

// wait 1 seconds for connection:
delay(10000);
}

printWifiStatus();

// print your WiFi shield’s IP address:
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());

Serial.print("Firmware version: ");
Serial.println(WiFi.firmwareVersion());

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(“WiFi shield not present”);
quit();
}

/*

  • Code commented out

Serial.println("\nStarting connection to server…");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println(“connected to server”);
// Make a HTTP request:
client.println(“GET /search?q=arduino HTTP/1.1”);
client.println(“Host: www.google.com”);
client.println(“Connection: close”);
client.println();
}
else {
Serial.println(“FAIL”); // <— always fails!!!
quit();
}
*/

}

void loop()
{
// if there’s incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
while (client.available()) {
char c = client.read();
Serial.write(c);
}

// if ten seconds have passed since your last connection,
// then connect again and send data:
if (millis() - lastConnectionTime > postingInterval)
{
httpRequest();
}
}

// this method makes a HTTP connection to the server:
void httpRequest()
{
// close any connection before send a new request.
// This will free the socket on the WiFi shield
client.stop();

// if there’s a successful connection:
if (client.connect(server, 80)) {
Serial.println(“connecting…”);
// send the HTTP PUT request:
client.println(“GET /latest.txt HTTP/1.1”);
client.println(“Host: www.arduino.cc”);
client.println(“User-Agent: ArduinoWiFi/1.1”);
client.println(“Connection: close”);
client.println();

// note the time that the connection was made:
lastConnectionTime = millis();
} else {
// if you couldn’t make a connection:
Serial.println(“connection failed”);
}
}

void printWifiStatus()
{
// print the SSID of the network you’re attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield’s IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print(“signal strength (RSSI):”);
Serial.print(rssi);
Serial.println(" dBm");
}

void quit()
{
while(true);
}

I am facing the same problem. My external python script is listening to the port that I am connecting on Arduino, but the client.connect kept failing. My Arduino is connected to the same network.

Same here. My client.connect() returns always false (except the cases when I want to connect to port 80 to any website). What does it mean?? Can someone explain, where can be the problem?