ethernet shield two client connections

Hello All!

I'm using the official ethernet shield as a client. I need to connect to 2 ports on the server (6000 and 8080). The connection to port 6000 opens, exchanges date and closes every few seconds. The connection to port 8080 is always on as long as there's data to transfer.

My question is: is it possible to have two connections opened at the same time? If so, do you see any reason on the code below for the shield not to connect to port 8080?

The code I wrote does the connection to port 6000 quite well but never seems to connect to port 8080 (I checked with net sniffer). Here are the relevant parts:

Client client(server,6000);
Client client2(server,8080);

...

void loop(){
//keep sending the IP address to the server
  if (client.connect()){
       delay(1000);
       client.println("10.0.0.15");
       delay(1000);
       c = client.read();
    Serial.println(c);//c will be either p (for play) or n (for noplay)
    client.println("bye");
    client.stop();
}
  else Serial.println("Connection to port 6000 is not available!");
//the section above works well
...
if (c == 'p'){ 
  if (!http_linked)
//this part of the code runs but I get no 8080 connection on the network sniffer
    if (client2.connect()){
      delay(10);
      http_linked = true;
    }
    else Serial.println("Failed connection to streaming server!");  
  }

...

  else {
   while (client2.available()){
      data = client2.read();
      Wire.send(data);     
   }
      Serial.println("I'm here 3. I get here, but still can't see any connection on port 8080...");
  }

The code seems to be alright and I can only think of problems making two connections at the same time to different ports braking its execution...

Please let me know if you have any idea of what might be happening :wink:

Many TIA,
RA

I have no idea if you can have 2 connections at the same time, but I would suggest getting rid of all your if/else statements & just try to have 2 connections open at the same time. In other words, test something simple to narrow down the problem. Even if you think those if/else statements should work, it's always better to narrow the scope of the problem (fixing bugs are always more work than writing the actual code) and then build on things once you know they are working.

Your if/else statements are a bit confusing. I'd suggest putting curly braces around all your if statements even if you think it should work. It's a bit odd to see a comment right below your if statement that doesn't have an explicit curly brace.