ESP8266 to ESP8266 communication using Arduino IDE I am trying to achieve communication between two ESP8266, ie one acts as a server and the other acts as a client, where i am passing the string from the server's serial monitor to the client. But the client is not receiving the string.

I have uploaded the server's and client's code below:

#include &lt;ESP8266WiFi.h&gt;
const char* ssid = "xxx";
const char* password = "xx";

WiFiServer server(80);
char inData[64];
char inChar=-1;

void setup() {
  Serial.begin(115200);
  delay(10);
  // Connect to 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");
  // Start the server
  server.begin();
  Serial.println("Server started");
  // Print the IP address
  Serial.println("ip address..");
  IPAddress ip(192,168,1,2);
  IPAddress gateway(192,168,1,1);
  Serial.print(F("selecting static ip to:"));
  IPAddress subnet(255,255,255,0);
  WiFi.config(ip,gateway,subnet);
  Serial.print(WiFi.localIP());
}

void loop() {  
  // Check if a client has connected
  WiFiClient client = server.available();
  byte numBytesAvailable= Serial.available();
  if(numBytesAvailable &gt; 0) {
    client.print("hi");
    int i;
    for (i=0;i&lt;numBytesAvailable;i++) {
      inChar= Serial.read();
      inData[i] = inChar;
    }
    inData[i] = '\0';
    client.print(inData);
    delay(500);
    client.flush();
    Serial.println(inData);
  }
  String line = client.readStringUntil('\r');
  Serial.println(line);
  delay(100);
}


Client code:

/*
 *  This sketch sends data via HTTP GET requests to data.sparkfun.com service.
 *
 *  You need to get streamId and privateKey at data.sparkfun.com and paste them
 *  below. Or just customize this script to talk to other HTTP servers.
 *
 */

#include &lt;ESP8266WiFi.h&gt;
void Readled(String line);
const char* ssid     = "xx";
int ledPin1 = 14;
int ledPin2 =  12;
int ledPin3 = 13;
int ledPin4 = 15;
String ON=String("ON");
String OFF=String("OFF");
char inData[64];
char inChar=-1;

void setup() {
  Serial.begin(115200);
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
}

void loop() {
  delay(200);
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect("192.168.1.2", httpPort)) {
    Serial.println("connection failed");
    return;
  }
  // This will send the request to the server
  client.print("hi");
  while(client.available()) {
    String Data = client.readStringUntil('\r');
    Serial.println(Data);
    client.flush();
    Readled(Data);
  }
}


This is the logic. Please suggest me where I am going wrong.
I don't like the order between two statements:

server.begin();
...
WiFi.config(ip,gateway,subnet);


Since you start the server and then modify the IP address, server may be "connected" to the wrong address. Try swapping these two statement groups - start the server after setting the IP address.

I don't know your WiFi router, but it might not like you arbitrarily changing your IP address like that.