[java] java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused)

I want to transfer some data between PC and a mobile phone with WiFi.

This is how I get the WiFi IP address:

String ip  = String.format(
                    "%d.%d.%d.%d",
                    (wifiInfo.getIpAddress() & 0xff),
                    (wifiInfo.getIpAddress() >> 8 & 0xff),
                    (wifiInfo.getIpAddress() >> 16 & 0xff),
                    (wifiInfo.getIpAddress() >> 24 & 0xff));

new Recive().execute(ip);

This is the code about sending a message to the PC:

Socket socket = null;
String message = "test\r\n";
protected Void doInBackground(String... urls) {
    try {
        Log.i("ip", urls[0]);
        socket = new Socket(urls[0], 2468);
        toserver = new DataOutputStream(socket.getOutputStream());
        toserver.writeBytes(message);

        toserver.flush();
        toserver.close();
        socket.close();
        return null;
    } catch (Exception e) {
        Log.i("e", e.toString());
        return null;
    }
}

But an error occurs,

java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused)

Besides, I use a android phone to run the app.

This question is related to java android networking wifi

The answer is


I was also getting the same issue I tried multiple IPs like my public IP and localhost default IP 127.0.0.1 in windows and default gateway but same response. but I forget to check by

C:> ipconfig

ipconfig cleanly say what is my actual IP address of that adapter with which I have connected like I was connected with Wifi adapter my IP address will show me as:

Wireless LAN adapter Wireless Network Connection:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::69fa:9475:431e:fad7%11
   IPv4 Address. . . . . . . . . . . : 192.168.15.92

I hope this will help you.


you can covert domain to IP address because every Domain have specific IP address, then you will solve that issue. I hope this will help you.


My problem was solved after turning Off Windows Firewall Defender in public network as I was connected with that network.


Why this might have happened:

  1. The server couldn't send a response: Ensure that the backend is working properly at IP and port mentioned.
  2. SSL connections are being blocked: Fix this by importing SSL certificates

Less likely:

  1. Cookies not being sent
  2. Request timeout: Change request timeout

first,i used "localhost:port" format met this error.then I changed the address to "ip:port" format and the problem solved.


A common mistake during development of an android app running on a Virtual Device on your dev machine is to forget that the virtual device is not the same host as your dev machine. So if your server is running on your dev machine you cannot use a "http://localhost/..." url as that will look for the server endpoint on the virtual device not your dev machine.


check the name of the database in a file where you established a connection.


I solved the same problem, I used a network connection through a proxy server, when I selected the option not to use proxies for internal and local connections, the problem disappeared


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to networking

Access HTTP response as string in Go Communication between multiple docker-compose projects Can't access 127.0.0.1 How do I delete virtual interface in Linux? ConnectivityManager getNetworkInfo(int) deprecated Bridged networking not working in Virtualbox under Windows 10 Difference between PACKETS and FRAMES How to communicate between Docker containers via "hostname" java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused) wget: unable to resolve host address `http'

Examples related to wifi

java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused) use "netsh wlan set hostednetwork ..." to create a wifi hotspot and the authentication can't work correctly Get SSID when WIFI is connected " netsh wlan start hostednetwork " command not working no matter what I try Enabling/Disabling Microsoft Virtual WiFi Miniport Connect Device to Mac localhost Server? How to calculate distance from Wifi router using Signal Strength? Connect Android to WiFi Enterprise network EAP(PEAP) Enabling WiFi on Android Emulator Android turn On/Off WiFi HotSpot programmatically