ESP32/ESP8266 connect to localhost server using WiFi

Hi, I have made a simple local server to receive the data from ESP and put it in data base
the server is working fine as I tested it using postman. the server is listening to port 127.0.0.1:3000

my problem is that client.connect(host,port) returns false.

#include "Arduino.h"

#include "WiFi.h"



WiFiClient client;
const IPAddress server(192,168,1,10);

const int httpPort = 3000;


const char* ssid = "******";
const char* password =  "********";
void setup()
{
  Serial.begin(115200);
  
  Serial.println();
  Serial.println("Booted");
  Serial.println("Connecting to Wi-Fi");

  WiFi.begin (ssid, password);
  WiFi.mode(WIFI_STA);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
    yield();
  }
  Serial.println("WiFi connected");

 if (client.connect(server,httpPort )){
 Serial.println("Client Connected");

 }


 else{
     Serial.println("No Connection");
  }


}

// The loop function is called in an endless loop
void loop()
{
//Add your repeated code here
}

firewall?

Juraj:
firewall?

Disabled

use #include <ESP8266WiFi.h>

and remove those arduino includes

Juraj:
use #include <ESP8266WiFi.h>

and remove those arduino includes

This is ESP32 WiFi library not Arduino WiFi library
I have removed the doubled "Arduino.h" the problem is not there

from esp8266 arduino core 2.3?

Juraj:
from esp8266 arduino core 2.3?

I have tested the provided example on ESP32 and ESP8266 on both platforms the connection to the localhost failed

for sure when I am switching the platforms for testing I change the WiFi library

WiFi.h for ESP32
ESP8266WiFi.h for ESP8266

I am using esp8266 core 2.2.0 and the latest for ESP32 core

ok. I understand.

the examples work? WiFiClient example?

Juraj:
ok. I understand.

the examples work? WiFiClient example?

Yes I can connect to any online host like "script.google.com" or sparkfun

the IP address is correct? in post text you have the loopback address and in sketch a real address.

Juraj:
the IP address is correct? in post text you have the loopback address and in sketch a real address.

IPv4 Address. . . . . . . . . . . : 192.168.1.10
Subnet Mask . . . . . . . . . . . : 255.255.255.0

I was disparate so I reset it manually :smiley: yes its correct

eahabissac:
IPv4 Address. . . . . . . . . . . : 192.168.1.10
Subnet Mask . . . . . . . . . . . : 255.255.255.0

I was disparate so I reset it manually :smiley: yes its correct

it is the server address, right? not the esp address?

the server is http or https?

Juraj:
it is the server address, right? not the esp address?

the server is http or https?

yes, my pc IP address which runs the local server

the postman url, if you test it from browser is http or https? why port 3000? it is unusual

Juraj:
the postman url, if you test it from browser is http or https? why port 3000? it is unusual

its http
3000 No reason,
its working fine with postman

UPDATE: I used Port Listener v1.03, to listen to port 3000 and the client connected successfully, but I still cant see why when I listen from the server I can not connect

I was out of ideas. So something with nonstandard port?

UPDATE: I used Port Listener v1.03, to listen to port 3000 and the client connected successfully, but I still cant see why when I listen from the server I can not connect

This sounds like a web server configuration problem. Can a web browser running on a computer different access the web server? If not, the web server may be configured to only allow access from the computer running the web server. Check the web server docs. In some systems, configuring the web server IP as 127.0.0.1 will cause the web server to reject connections from all computers except the computer running the web server.

When I used AMMPS a long time ago, it did not like non-standard port numbers, that is, anything other than 80 and 8080. I would give port 80 try just in case this issue exists with the web server.

gdsports:
This sounds like a web server configuration problem. Can a web browser running on a computer different access the web server? If not, the web server may be configured to only allow access from the computer running the web server. Check the web server docs. In some systems, configuring the web server IP as 127.0.0.1 will cause the web server to reject connections from all computers except the computer running the web server.

When I used AMMPS a long time ago, it did not like non-standard port numbers, that is, anything other than 80 and 8080. I would give port 80 try just in case this issue exists with the web server.

Thank you, it worked now I reconfigured my local server with 0.0.0.0 IP instead of 27.0.0.1