How to use two ESP8266 to send data back and forth

Okay so i have a sensor, arduino, and ESP8266 on one side and i need to send the sensor's info to another arduino with a esp8266. The question is how do i begin to do that. I just got these two esp8266 chips and have zero knowledge of networking or this chips libraries. Thanks in advance.

I added a drawing just incase it doesnt make sense.:slight_smile:

Untitled.png

Have a look at this:

There are examples for the ESP8266, but I am using the examples as basis for exchanging data between two ESP32.
Cannot help with the ESP8266 as I have not tested the examples for this.

WiFiClient object wraps a TCP socket. A normal TCP socket is connected to IP address and port. WiFiServer starts a listening socket on a port. If server on listening socket is contacted by a remote client socket, it creates a local socket connected with the remote client socket on a free port and returns a WiFiClient object wrapping the socket. Everything you write or print to a WiFiClient is send to that one remote socket.

If your client esp8266 creates a WiFiClient and connects it to IP address and port of the WiFiServer on your 'server' esp8266, then you get there a WiFiClient from server.available() and this two WiFiClient objects are connected. What you write/print on one side you read only from the WiFiClient object on the other side.

client socket

   if (client.connect(serverIP, PORT)) {
     client.print("request\n");
     String response = client.readStringUntil('\n');
     Serial.println(response);
     client.stop();
   }

server side

   WiFiClient client = server.available();
   if (client && client.connected()) {
     String request = client.readStringUntil('\n');
     Serial.println(request);
     client.print("response\n");
     client.stop();
   }