Slow connection to local server but fast to remote
Posted: Sun Jan 03, 2016 5:25 pm
When I run the sketch below to connect to adafruit it takes about 50ms. When I run it to connect to my local server, XAMPP on my PC, it takes 1000ms. When I connect to the local server from my other PC it loads almost instantaneously so it's not the local server that is slow. Does anyone have any idea why this might be?
Code: Select all
/*
* Simple HTTP get webclient test
*/
#include <ESP8266WiFi.h>
const char* ssid = "virginmedia545641";
const char* password = "mypassword";
const char* host = "192.168.0.10";
//const char* host = "www.adafruit.com";
String url = "/electronics/test.php";
//String url = "/testwifi/index.html";
const int httpPort = 80;
String remoteData;
void setup() {
Serial.begin(115200);
delay(100);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// Use WiFiClient class to create TCP connections
WiFiClient client;
unsigned long testStartTime = millis();
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(1);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
remoteData = client.readStringUntil('\r');
}
Serial.println(millis() - testStartTime);
//Serial.println(remoteData);
//delay(3000);
}