Arduino Wifi Shield and Library support for Multi port/socket communication

Hi ,

I am using a combination of an arduino as well as a Wifi shield for one of my hobby project. I am need to run a Wifi webserver on the arduino side and have 3 of the client connect to it on different ports.

So basically first i started with the Arduino Ethernet shield before having access to the wifi shield and here is what i did :

I initiated four server on four different ports and then everything works fine and four of the clients can independently connect to the servers running on the arduino and all is well. Just to give an idea i have provided below a working code on the ethernet shield.

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

// network configuration.  gateway and subnet are optional.

 // the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
//the IP address for the shield:
byte ip[] = { 192, 168, 0, 20 };  

int numTCPIPpairs = 3;

EthernetServer server[numTCPIPpairs] = {62200, 62201, 62202};

void setup()
{
  Ethernet.begin(mac, ip);
  // start listening for clients
  for (i=0;i<numTCPIPpairs;i++)
  {
    server[i].begin();
  }
  
}

void loop()
{
for (i=0;i<numTCPIPpairs;i++)
  {
    server[i].print(i);
  }
      delay(10);
 }
  
}

Now that this is working fine i tried to move this code to the wifi shield and here is how the code looks like

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


char ssid[] = "NETGEAR22";      // your network SSID (name) 
int status = WL_IDLE_STATUS;
int numTCPIPpairs = 3;
WiFiServer server[numTCPIPpairs] = {60001, 60002, 60003};

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"); 
    // don't continue:
    while(true);
  } 
  
  // 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);

    // wait 10 seconds for connection:
    delay(10000);
  } 
  IPAddress ip1;
  ip1 = WiFi.localIP();
  Serial.println(ip1);
  
  for (i=0;i<numTCPIPpairs;i++)
  {
    server[i].begin();
  }
  // you're connected now, so print out the status:

}


void loop() {
  for (i=0;i<numTCPIPpairs;i++)
  {
    server[i].print(i);
  }
      delay(10);
 }
    Serial.println(server[2].status());
    
}

Here is where i see an issue. The above code works only for 2 ports meaning when the numTCPIPpairs is 2. When i try more than 2 ports the code compiles fine and i am able to download code onto the hardware but the clients (I used wireshark as well as processing code ..etc ) are not able to connect to the sockets.

Is there a maximum limitation of the sockets on wifi that can be used on the wifi shield. From the libraries it looks like the maximum is 4 but i also found a strange comment on one of the library files of Wifi in the file Wifi.cpp saying that
// XXX: don't make assumptions about the value of MAX_SOCK_NUM.

Is there some one who really knows what is the limitation/threshold on the maximum sockets ?

PS: please note that i have successfully downloaded and verified that i have the latest firware on the wifi shield as well as the latest (Arduino 1.0.5 and Wifi libraries).

Cheers,
Sreeram_Mohan