WebServer to output value with every query to client

Hi everyone,

I am fairly new to WebServer communication and I am trying to build an Arduino WebServer that outputs a value each time it is queried by a client running on python. I am running this on an Arduino Uno R3 with an Ethernet Shield 2 (with W5500). Currently, I am aiming for a number to be sent to the client (currently just 1.0), every time a message is sent to the server, the received message is then output to a file. I have been able to successfully open a connection with my client, but it remains open so instead of getting something like this

1.0
1.0
1.0
1.0

I obtain this:

1
.0
1.0
1
.0
1

How can I set the connection up such that the WebServer only sends the 1.0 once each time the client queries it?

Here is my current Arduino code:

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xA8, 0x61, 0x0A, 0xAE, 0x69, 0x13};
IPAddress ip(198, 162, 1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);


void setup() {
  Serial.begin(9600);  //Starting serial monitor

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Ethernet WebServer Example");

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start the server
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}



void loop() {

  EthernetClient client = server.available();
  if (client)
  {
    boolean currentLineIsBlank = true;
    while (client.connected())
      if (client.available())
        {
          Serial.println("new client");
          // give the web browser time to receive the data
          delay(1);
          client.print(1.0);
          delay(2000);
          Serial.println();
          // close the connection:
          //client.stop();
        }

  }
 
}
ยดยดยด

Nice.
Same topic 3rd time in a row.

In that implementation of webserver, you have NOTHING.
No HTTP header, no RULES for communication, nothing.
You are sending there some 1.0 string without knowing encoding, rules of transfer.

What is content type? Binary, html, plaintext, image? You havent specify anything.
Also, how many connections have you open? You havent closed connection.
I am using webserver with Arduino and Wiznet W5500 shield without any problem, when I specify content type and http header etc.

So, problem can be at webserver or at client, because client have no idea what he is receiving, because webserver is sending only some string.

You can open Ethernet library examples to understand how webserver works.

Yes, I know. However I am a complete newbie when it comes to Arduino and socket communication in general.

Regarding the content type, I would be aiming for ASCII, since all I would want this to do is send a value as a floating point number to a client, where is it output to .csv file by said client. For HTTP, I was under the impression that I would not need it since I do not want this to open any kind of webpage to display the incoming data from the WebServer, however I maybe wrong in this regard. Every time a request is sent to the WebServer from the client, the WebServer simply just sends a value back to the client, which is then sent to the .csv file, as described earlier.

For the number of connections, I would only be using one connection at any one time. From your statement, it seems like I would have to open and close a connection each time it is receives a signal from the client, such that it only sends the value once. Is this line of thinking correct?