Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't stop client when client isn't receive data #58

Open
ashot5706 opened this issue Jun 17, 2018 · 0 comments
Open

can't stop client when client isn't receive data #58

ashot5706 opened this issue Jun 17, 2018 · 0 comments

Comments

@ashot5706
Copy link

I was run server on Wemos D1 mini, when ESP transmit TCP packet, and client isn't received, the ESP was hanged, and only reset help. Who know how to check while "client.printing" is the client available yet or not?
the Code below

#include <ESP8266WiFi.h>

const char* ssid = "my_network";
const char* password = "mynetpass";

WiFiServer server(80);
void setup() {
  Serial.begin(115200);
  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(WiFi.localIP());
  server.begin();
  Serial.println("Server started");
}
WiFiClient client;
unsigned long angam=0;
unsigned long jam[2]; // debug
// unsigned long jam;
void loop() {
  jam[0] = millis();//debug
  //jam = millis();
  client = server.available();
  if(!client){
    return;
  }
  jam[1] = millis(); // debug
  Serial.println("server is available"); // debug
  angam++;
  Serial.println();
  Serial.println();
  Serial.println();
  while(!client.available()){
    delay(1);
    if(millis() - jam[1] > 5000) return;
  }
  Serial.print("client is available  "); //debug
  Serial.println(millis() - jam[1]); //debug
  Serial.print(client.remoteIP());
  Serial.println("   " + client.readStringUntil('\r'));
  Serial.println("start flush"); //debug
  jam[1] = millis(); //debug
  client.flush();
  Serial.print("flush end  "); //debug
  Serial.println(millis() - jam[1]); //debug
  Serial.println("Start client print  "); //debug
  client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<html>");
  client.print("Server is ready " + String(angam) + "\n");
  client.print("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, ");
  client.print("</html>\n");
  Serial.println("Client print succesfull");
  Serial.println(millis() - jam[0]); //debug
  //Serial.println(millis() - jam); 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant