-->
Page 1 of 1

Trouble in C#, Receiving data from esp8266

PostPosted: Thu Aug 31, 2017 4:06 am
by mahdinga
Hello guys!!!
what is the best way to send and receive information from esp8266 in C# and showing it???
i used some codes but they didn't work:(
on the ESP:
Code: Select allvoid loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  while (!client.available()) {
    delay(1);
  }
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  client.println(Data);

}

Wifi Connection is valid and the ip address is known.this code waits for a request and shows the request on SerialTerminal and send the "Data" to client.


and the PC side using System.Net.WebClient:
Code: Select allWebClient wc = new WebClient();
byte[] Data = wc.DownloadData("http://192.168.1.100/This_is_a_test");
File.WriteAllBytes(@"D:\A.txt", Data);


the problem is that when you request on a web explorer(Like mozila or anything) on a PC is in the same LAN it works great. it shows the Data and Serial shows the request that you entered on web explorer.

but the C# codes give me an error:
The server committed a protocol violation. Section=ResponseStatusLine

however the request that i entered in the C# codes ("This_is_a_test") is shown in the SerialTerminal.


is there anyway to communicate between esp and a C# application without these errors??? :?: :?: :?:

Re: Trouble in C#, Receiving data from esp8266

PostPosted: Thu Aug 31, 2017 10:33 am
by martinayotte
Your C# program is using HTTP transaction and expect an answer from the ESP server, but you don't provide/send any ...
Simply adding a response should fix it :
Code: Select allclient.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n")