Arduino losses connection with server (Apache Tomcat)

Thanks for your reply! I realized I was somewhat vague with my question and I also explained it wrong....

The fact is, the Arduino reads the RFID card and sends the message just fine. The server receives the RFID tag and validates the user. The issue appears when the Arduino moves on to detect the presence of an object with an Ultrasound Sensor. That is when the Arduino losses the connection to the server...

Here's the addition info:

PaulS:

We have an Arduino

There are roughly a dozen models. You have which one?

We have an Arduino UNO (Rev 3) with an Ethernet Shield (also Rev 3)

with an RFID card reader

Which one?

How is it connected?

It's a Sparkfun ID-12 RFID Reader, connected to pin 0 (RX)

which sends the RFID tag

How does it get it?

It gets the tag via the ID-12 reader, the Arduino detects there is a card and then sends the HEX code to validate the existence of the card. The server then replies if the card (hence the user) is allowed to move on or not.

If the user is allowed, the Arduino carries on to detect the presence of an object (with an HC-SR05 Ultrasound Sensor, connected to pins 5 and 6). This is when the connection to the server is lost, and the Arduino is unable to send that info. It just hangs...

The first connection to the server -in which the Arduino sends "I'm ready" via GET- is made flawlessly.

Why is it doing this?

This is being done to let the server know when is the Arduino ready to begin reading cards and validating users.

But, when the Arduino reads the RFID card, it cannot send back the message to the server

Back to the server? Did the server ask it to read the RFID card? Servers don't generally ask clients to do stuff. So, the client is sending a response back.

If it is sending a GET request, with an RFID tag, that is a different story.

Yes, it is sending a GET request with the RFID card as string. The server waits for the string and validates the user.

What does your code look like?

Code:

boolean sendMessage(String aMessage){
    boolean isConnected = connectToServer();
    if (isConnected){
      Serial.println("Conection established"); 
      client.println(aMessage);
      client.println();
      Serial.print("Message sent: ");
      Serial.println(aMessage);
    }
    else {Serial.println("Conection fail timeout");}
   return isConnected;
}

// Connects to the server 
boolean connectToServer(){
    Serial.println("Connecting to server...");
    client.connect(server, PORT);
    int attemptNumber = 0;
    boolean stillTimeOut = attemptNumber < MAX_ATTEMPS;
    boolean cantConnect = !client.connected() & stillTimeOut;
    while (cantConnect){
      stillTimeOut = attemptNumber < MAX_ATTEMPS;
      cantConnect = !client.connect(server, PORT); & stillTimeOut;
      attemptNumber++;
      Serial.print("Conecting... Attempt number: ");
      Serial.println(attemptNumber);
    }
    return client.connected();
}