Here is my test code. Change the network settings to yours.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip( 192,168,2,2 );
IPAddress gateway( 192,168,2,1 );
IPAddress subnet( 255,255,255,0 );
EthernetServer server(80);
EthernetServer server2(8080);
void setup()
{
Serial.begin(9600);
// disable SD if one in slot
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Ethernet.begin(mac, ip, gateway, gateway, subnet);
digitalWrite(10,HIGH);
delay(2000);
server.begin();
server2.begin();
Serial.println(F("Ready"));
}
void loop()
{
EthernetClient client = server.available();
if(client) {
boolean currentLineIsBlank = true;
boolean currentLineIsGet = true;
int tCount = 0;
char tBuf[64];
Serial.print(F("Client request: "));
while (client.connected()) {
while(client.available()) {
char c = client.read();
if(currentLineIsGet && tCount < 63)
{
tBuf[tCount] = c;
tCount++;
tBuf[tCount] = 0;
}
if (c == '\n' && currentLineIsBlank) {
// send a standard http response
Serial.println(tBuf);
Serial.print(F("POST data: "));
while(client.available()) Serial.write(client.read());
Serial.println();
Serial.println(F("Sending response"));
client.println(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html>"));
client.println(F("<body><H1>TEST Server 1</H1>"));
client.println(F("</body></html>\r\n"));
client.stop();
}
else if (c == '\n') {
currentLineIsBlank = true;
currentLineIsGet = false;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
Serial.println(F("done"));
}
client = server2.available();
if(client) {
Serial.println(F("Server2"));
boolean currentLineIsBlank = true;
boolean currentLineIsGet = true;
int tCount = 0;
char tBuf[64];
Serial.print(F("Client request: "));
while (client.connected()) {
while(client.available()) {
char c = client.read();
if(currentLineIsGet && tCount < 63)
{
tBuf[tCount] = c;
tCount++;
tBuf[tCount] = 0;
}
if (c == '\n' && currentLineIsBlank) {
// send a standard http response
Serial.println(tBuf);
Serial.print(F("POST data: "));
while(client.available()) Serial.write(client.read());
Serial.println();
Serial.println(F("Sending response"));
client.println(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html>"));
client.println(F("<body><H1>TEST Server 2</H1>"));
client.println(F("</body></html>\r\n"));
client.stop();
}
else if (c == '\n') {
currentLineIsBlank = true;
currentLineIsGet = false;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
Serial.println(F("done"));
}
}