Monitor distance sensor with Ethernet Shield

Hi guys, my situation is as follows:
I have a HCSR04 Distance Sensor, MEGA Arduino and Ethernet Shield.
My goal is to monitor the distance sensor with Ethernet. I have the codes of distance sensor and Ethernet communication working separately, however, to try to join the code, I’m not getting more be answered values of distance sensor, it seems that it always returns 0. It looks like I’m probably leaving something go in the code that the shield’re not leaving the sensor to work properly…
The same thing happens with the compass.

//--------------- INCLUDES ----------------------
#include <Ethernet.h>
#include <SPI.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>
#include <SD.h>
#include <Wire.h>

//---------------- DEFINES ----------------------
// Sensor Ultrasonico
#define echoPin 46 // pino Echo
#define trigPin 44 // pino Trigger

//----------- SENSOR ULTRASONICO ----------------
int alcanceMax = 200; // Alcance maximo necessario
int alcanceMin = 0; // Alcance minimo necessario
long duracao, distancia; // Duracao usada para calcular a distancia

#define address 0x1E //0011110b, I2C 7bit address of HMC5883
int x,y,z; //triple axis data

EthernetServer server(23);
String content;
File myFile;
int ledPin = 42;
int outputpin = 0;


  
void setup()
{
  IPAddress ip(10, 107, 134, 70);
  byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x81, 0x88 };
 
  Ethernet.begin(mac, ip);
  server.begin();
  if (!SD.begin(4)) 
  {
    return;
  }
  
  Serial.begin(9600);
  
  // Sensor Ultrasonico
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}
///////////////////////////////////////////////


void loop()
{
  waitIncommingConnection();                                                             
}

void waitIncommingConnection()
{
  String pwd            = "";
  String inData         = "";
  EthernetClient client = server.available();
  
  
  if ( client  )
  {
    while ( client.connected() ) 
    {      
      if ( client.available() > 0)
      { 
        char recieved = client.read();
        inData += recieved;                       
        if (recieved == '\n')
        {                           
          switch( inData[0] )
          {                            
            case (char)'o' : 
              client.println("o");
              digitalWrite(ledPin, HIGH);
            break;

            case (char)'f' :
              client.println("f");
              digitalWrite(ledPin, LOW);
            break;
  
             case (char)'c' :
               // Sensor Ultrasonico
               digitalWrite(trigPin, LOW); 
               delayMicroseconds(2); 
               digitalWrite(trigPin, HIGH);
               delayMicroseconds(10); 
               digitalWrite(trigPin, LOW);
               duracao = pulseIn(echoPin, HIGH);
               distancia = duracao/58.2; //Calcular distancia (em cm) baseado na velocidade do som
               
               //client.println(getTemperature());
               if (distancia >= alcanceMax || distancia <= alcanceMin){
                 // Enviar numero negativo para o computador indicando "Fora da faixa" 
                 client.print(-1);       
                }
                else {
                  // Enviar a distancia para o computador
                  client.print(distancia);     
                }
              break;
             
            case (char)'*' :
              Logout(client);  
            break;
          
            default:
               client.println('d');
            break;
          }
          inData = ""; 
        } // fim if
      } // fim if
    } // fim while
  } // fim if
  else
  {
   client.println('v');
  }
} // fim waitIncommingConnection()

void Logout(EthernetClient client )
{ 
  client.print('x');
  client.stop(); 
} // fim Logout()

Can anyone help me?

Thank you