The client failed to establish a connection to the local address localhost:3000.
The error encountered was:
dial tcp [::1]:3000: connectex: No connection could be made because the target machine actively refused it.
How can I solve it?
Change your localhost:3000 address to local IP address for example 192.168.1.15:3000 etc.
Your server and client must be in same network
Emulator
On an emulator the localhost is accessible using the IP 10.0.2.2 .
So localhost:3000 will be 10.0.2.2:3000 in your emulator.
Physical device
First of all you must be on the same network to be able to connect.
Get the PC ip using ipconfig (windows) and ip a or ifconfig (linux)
Connect to the PC localhost using it's ip. i.g 192.168.2.121:3000
(your firewall must be OK with this)
If you are trying to connect using code, same things are needed for this
Related
I am developing a SSH app on Android using Android Studio and Java. The SSH code I am using is from the library JSch.
Right now I am having a issue connecting to my host SSH server. I can connect to it from other virtual machines and computers but my emulator is not able to. I am trying to use the ip 10.0.2.2 to connect to localhost but I continue to get failed to connect to /`0.1.1 (port 22) from /:: (port 58062): connect failed: ECONNREFUSED (Connection refused).
I know the Windows host SSH server is working. If I use ADB to get into the emulator I can ping 10.0.2.2 without issue. I feel like it is some sort of limitation inside the virtual network that the emulator is setup in however I am not sure. Does anyone know of any ways to make my Android SSH connect to my host windows SSH server?
I can't connect (using JDBC) to a MySQL database hosted on my home computer(windows 8.1), from a laptop(Windows 7) connected to another network. As a connection url i use "jdbc:mysql://192.168.0.102:3306/.." and I've granted all privileges to the user i'm trying to connect with. I have commented #skip-networking and #bind-address (I also tried with bind-address=0.0.0.0).
The thing is, if I bring the laptop to my home (on the same network as the computer hosting the database), it works just fine, but it doesn't connect anymore when the laptop it's connected to external networks.
Thank you!!
IP addresses 192.168.XXX.XXX are local addresses, which means they can't be reached from beyond the boundary of the router, Unless you set up port-forwarding on the router.
When you connect from outside the network on a particular port on your WAN address the connection will be forwarded to the pc/port you set up in the router.
There are some very good online tools that help you with the configuration like http://portforward.com/.
Be advised that forwarding / opening ports on your router might make your network more vulnerable to hacking.
2 Problems.
*1
U Try to connect to the Database using the localNetworkIP.
open https://www.whatismyip.com/ on the Host, then u get the Internet IP of the Computer.
CAREFULL, most likely ur Internet IP Changes over time ( every 24hours) or u have a static IP. if not u have to use a DynDNS Provider to connect ur changing ip addresses to a DNS Domain.
*2
The PORT 3306 has to be open in the router of the HOST.
I need to connect an android device to my java program via socket connection. The device is working as server. The problem is that while trying out socket connection I need to give IP address and port number of server.
Is there something like a static IP address for an Android device to connect? If not, is there any alternative way to establish a socket connection between the device and my program?
As the device has to have a connection to the same network as the computer, it has to have an IP address configured. So you have to use that one.
The used port is defined by the server application running on your device.
If you have the problem that anyhow a normal network connection is not possible, but you have an ADB connection, you can forward local pots to the device and let your server listen:
http://developer.android.com/tools/help/adb.html#forwardports
Over a mobile connection (GPRS, EDGE, UMTS, HSDPA) there will be no practicable way to establish a connection from somewhere to your device (instead you have to do it the other way, while canceling the whole client-server directive), in cause of the used IP sharing. In that case you have a problem of which I'm not aware if it's possible in general, not to mention how you could achieve this.
Otherwise you simply have to configure a static IP for your device when connected to your local network, or you have to evaluate the actual IP of your device every most of the time, while using it with this configuration:
Resolve it by the device itself
Resolve InetAdress from DhcpInfo
Documentation for DhcpInfo
Resolve by using ADB command
Hello world, I made an instant messenger with the server and the client that runs on a localhost, but I want to put the client on another computer but it cannot connect to the server without the localhost, please can I get some help(codes) that i can use to connect the client on another computer to the server on my own computer without the use of a localhost.
Use
ipconfig
command on Windows (in command-line) to get your IP address.
Get the Ip Address of the server machine, and replace the "localhost" in the client code with the Server IP.
I have a play application connecting to a database at 1.2.3.4 but for some reason Play! (and other java apps too) cannot connect to it.
I did try editing the hosts file and setting a name for the IP like app01 1.2.3.4 however it only worked on the box where the DB was hosted and it didn't work for external machines. I can confirm that the right port is open in iptables and I've tried restarting it, too.
If I ping postgres at port 4567 at 1.2.3.4 from the same box, it works. But setting the same IP address in my java apps fail. What's wrong? Is it permissions or iptables issue? Thanks.
Stack trace:
Caused by: java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.<init>(Socket.java:392)
at java.net.Socket.<init>(Socket.java:206)
at org.postgresql.core.PGStream.<init>(PGStream.java:62)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
... 35 more
Can you connect to your DB via pgadmin (http://www.pgadmin.org/)?
Can you telnet from your machine on to the DB Server on the given port (telnet 1.2.3.4 4567)?
If you cannot telnet maybe the DB Server is blocking your connections?
Have you set any proxy server either only for java or only for rest of the system?
From the exception it seems more of a networking issue than anything with java...
Can you check firewall settings on the db server. You can try by telnet to check whether you are able to connect or not.
If you're behind a router you WILL BE ABLE to ping it from another local machine (usin the local IP), but you might not be able to ping from the outside if you are not port-forwarding correctly (You can configure this from your router).
Another thing to take in mind is that you CAN'T ping your own external IP from within the network, that means that you can ping 192.168.1.100 (Server) from 192.168.1.xx (Client), but you can't ping 72.15.xx.xx (port-forwarded to 192.168.1.100) from 192.168.1.xx (Client).
In order to do this you have to use an external tool, there are many webs that can do this for you, here's the one that I use:
http://www.yougetsignal.com/tools/open-ports/
If it says the port is open then it is open and it should work now, if it shows closed then you should double check that your firewall is allowing the data, maybe shut it down temporary to see it thats the prob.
If you need help adding a port exception to your firewall or forwarding a port from your router just tell me which distro/routerModel you're using and I'll try to dig some more info for you.