Problems combining Servo with Ethernet Shield

I have a servo (pin 9) connected to an Arduino Mega which is connected to an Ethernet port and routed off to my PC. My desire is that when I send a page request through the Ethernet shield, I can set the servo to point in a specific direction. I am having problems getting the servo and Ethernet code on the Arduino to work together, and I don't know why. If you have any example code that combines the Ethernet protocol and a servo command, I'd greatly appreciate it

The command for where the laser is to point is tacked on to the URL on the page request sent to the Arduino (characters 10-12). At the end of reading and replying to a packet, the servo is set to a specific position. However, I find that after the first attempt to point the laser (after the first page request) I can no longer get a response from the Arduino (it hangs, as if the server.available() method never triggers the page request). If I comment out the command myservo.write(deg); the code will function normally (the Arduino responds to three successive page requests), although the laser will not move. I thought this might have to do with how long the myservo.write(deg); takes to execute, but it only takes 12ms at most (including debug print statements to the terminal) and the code continues to work with the command myservo.write(deg); replaced with a delay(50);

I have tried this code with the Servo connected to pin 9 as well as connected to pin 3, but I encounter the same problem both times.

My only thought is that there must be some conflicting code between the Ethernet and Servo classes, so when the Servo class is called, it interrupts the functions of the Ethernet class, preventing it from detecting future page calls, but this doesn't make sense to me since I call the Servo class in the initialization method, meaning that if this were the case, I'd never be able to get the Ethernet to work so long as I left that intiial call uncommented, so I am at a loss as to how to fix this problem. Thank you for your assistance.

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0, 42 };

//pins
int servoPin=9;

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
Server server(80);
Servo myservo;
int laserPos = 90;
int motorControl=0;
int motorDist=0;

void setup()
{
  Serial.begin(9600);
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  myservo.attach(servoPin);
  laserServo(laserPos);
}

void zeroVars()
{
    laserPos = 0;
 motorControl=0;
 motorDist=0;
}


void loop()
{
  // listen for incoming clients
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    zeroVars();
    int index=0;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        index++;
        if(index>=10&&index<=12)
        {
          int temp=c-48;//char to int
          //Serial.println(laserPos);
          laserPos+=temp*(index==10?100:index==11?10:1);
        }
        if(index==18)
        {
          motorControl=c-48;
        }
        if(index>=24&&index<=26)
        {
          int temp=c-48;//char to int
          motorDist+=temp*(index==24?100:index==25?10:1);
        }
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("
");
          }
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.flush();
    client.stop();
    Serial.println("A: ");
    Serial.println(laserPos);
    laserServo(laserPos);
    Serial.println("B");
  }
}

void laserServo(int deg)
{
  if(deg>=0&&deg<=179)
  {
    Serial.println("C: ");
    Serial.println(millis());
    myservo.write(deg);
    Serial.println("D: ");
    Serial.println(millis());
  }
}

Moral of the story: don't plug the Servo control pin into a digital output from the Arduino. I'm guessing it draws too much current and prevents the board from operating. Depending on whether or not I have the servo control pin coming out of the Arduino connected to my board, my code alternately works and does not work. I'm going to be trying this setup with an H-bridge to control the servo and see if that fixes the problem.

Or more specifically, the 5V supplied to the Servo cannot be drawn from the Arduino 5V output when the Arduino itself is powered over a USB connection. By connecting the Servo to an independent 5V power source (and connecting the grounds between the Arduino and the external source) the setup worked as intended.

Below is some test code you can use to test your servo. I don't think connecting the servo control pin to the digital pin is your problem. The reference to using an h-bridge with your servo indicates you may not understand how a servo works. Get the servo working then worry about the ethernet shield (which shouldn't be difficult to do).

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(2000); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  // allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n = readString.toInt();

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  } 
}