[solved] WifiConnect Problem hitting TCP port after WL_CONNECTED

I’m new to arduino. Running the Arduino Uno + WiFi Shield.

I’ve snagged a sample from the examples to demonstrate my problem. (and to attempt to make sure I wasn’t missing anything with my actual code.)
I’m able to connect to my wifi network. I’m able to ping the arduino from other network nodes.

However, from the arduino I’m unable to connect to a port on a server to send a packet.
Am I missing something?

No issues telneting to the port from other machines, I’m able to type a string in and it shows up in my debug screen on the server.
Tried a tcpdump on the server, no hits; the only results from the arduino’s IP were arp requests (when it was obtaining DHCP address).

Thanks for any help you can provide.

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

char ssid[] = "myssid";          //  your network SSID (name) 
char pass[] = "key";   // your network password

int status = WL_IDLE_STATUS;
//char servername[]="google.com";  // remote server we will connect to
IPAddress servername(192,168,1,79);

WiFiClient client;

void setup() {
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID: ");

  status = WiFi.begin(ssid, pass);
  if ( status != WL_CONNECTED) { 
    Serial.println("Couldn't get a wifi connection");
    // don't do anything else:
  else {
    Serial.println("Connected to wifi");
    Serial.println("\nStarting connection...");
    // if you get a connection, report back via serial:
    if (client.connect(servername, 8889)) {
          Serial.println("not connected");

void loop() {


results in:

Attempting to connect to WPA network…
SSID: myssid
Connected to wifi

Starting connection…
not connected

Resolved by reverting to Arduino IDE 1.0.3 and recompiling.

Have you try to connect to the server with another device??? Cause your code look correct.

I sure have, multiple other devices. The service I’m hitting works fine from other computers.

I got a feeling that you problem is here

IPAddress servername(192,168,1,79);

Where you ider tel the name of the computer to get his ip address or straight ip address. Well by judging the h file any way

Let’s get back at the WiFiWebClient example:

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

char ssid[] = "yourNetwork"; //  your network SSID (name) 
char pass[] = "secretPassword";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void setup() {
  //Initialize serial and wait for port to open:
  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"); 
    // don't continue:
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
  Serial.println("Connected to wifi");
  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");

void loop() {
  // if there are incoming bytes available 
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println("disconnecting from server.");

    // do nothing forevermore:

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

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

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

Ok it all look legit, let's see do you know the Ip of you wifi shield? Can you Ping it? And most important is the network mask set right? Maybe you wifi box give out 192.168.0.*** address with a network mask of then the shield wont see the computer?

Cause for what I see your code should work fine. Could you not set the Ipaddress staticaly at least for debug.

Hi Frederic,

I did try the example you provided. Same result with both IP and Hostname for google.

Definitely the correct IP for the arduino, able to ping, when I remove power from the arduino, ping fails. So it's definitely on my network.

Attempting to connect to SSID: myssid Connected to wifi SSID: myssid IP Address: signal strength (RSSI):-67 dBm

Starting connection to server...

disconnecting from server.

For fun, I'm going to adjust wireless settings on my router.

If it does not connect to google, the problem is on your network, I totally agree. Stop messing with your poor Arduino, flash has a limited life time ;)

Maybe Firewall?

Haha, I have a spare arduino if I break the flash. :)

I'm not having trouble with any other devices, Oh well. No firewalling between devices, just standard nat router out to the internet (seem to be no issue there). Switched from 802.11ngb to only 802.11gb I will try it on another wireless network to see if I have the same issue.

Thank you for your help.

I did add in another check and it's getting the correct IP's set by DHCP:

Attempting to connect to SSID: myssid Connected to wifi SSID: myssid IP Address: Subnet Mask: Gateway: signal strength (RSSI):-70 dBm

Starting connection to server...

disconnecting from server.

I don't know why, but it kinda piss me off to know the the official WiFi board does not work with the official démo program. lol

These WiFi board cost a fortune and they say that it's suppose to be a breeze to make them work. That why I prefer to work with modules. At least if I get trouble I can just blame my self for not paying the extra and just beat my brain until it finally work.

My favorite:


My friend broth his at home, I saw it work, It work super well, I got one comming by the mail. I'll start developing for it as soon as i get it. He make every thing with those, so will I.

I seem to be lucky and have found a bug :slight_smile:

Reverting to Arduino IDE 1.0.3 fixed the issue.

Same file, compiled in 1.0.3 Resulted in:

Attempting to connect to SSID: myssid
Connected to wifi
SSID: myssid
IP Address:
Subnet Mask:
signal strength (RSSI):-68 dBm

Starting connection to server…
connected to server
HTTP/1.1 200 OK
Date: Sun, 18 Aug 2013 01:37:36 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=a25fdfc02c43a338:FF=0:TM=1376789856:LM=1376789856:S=CXF_aBQn_T0LUFe4; expires=Tue, 18-Aug-2015 01:37:36 GMT; path=/; domain=.google.com
Set-Cookie: NID=67=FUt547y1K8UYJ2-WsYbz3g6nuxhknrUDS0F8wNmxETeAD5Qg0JWEggy-20CCghBxKYDvJg2mga4MVwPu3m4Iow4CVxt6rsbjaCZQq2VSaxmBNAPdW9p04kpZKktqz5AH; expires=Mon, 17-Feb-2014 01:37:36 GMT; path=/; domain=.google.com; HttpOnly
P3P: CP=“This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info.”
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic
Connection: close

<!doctype html>…

I see, so I was right to think that the 1.0.5 was kinda buggy. I felt that some thing was wrong and now you confirm.

They add some much stuff to fit with all the new hardware that it lost stability. humm

Well good, this is usefull to know. I kinda happy I kept the old version to.

It’s like windows, the more they add stuff, the less it work well. Although i’m not sure that windows has ever worked well lol :wink:

Ha true. May try linux :slight_smile:

Thanks again for your help. Always good to have someone else put eyes on things.

Hey, that what the community is for. (y)

Don't forget give you conclusion for the new guy. :) And to marked it solved in you title.