Java - Connecting a client to a server without the localhost - java

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.

Related

Unable to connect client program to server program over WAN

I have created a client server program on java language with serversocket and socket classes with datainputstream and dataoutputstream for sending and receiving data.
But the problem is that when I run it on LAN(local area network) or localhost it works properly but when I try to connect client with server over WAN (wide area network) it doesn't even connects to server
And to connect it over WAN I have entered ip address of server side program as parameter of socket class's contractor ex: socket s= new socket(ipadd,port); and it doesn't connects to server without any error or something
So please help me out I am stuck on this problem from a long time.
This is my server side program code
This is my client side program code
You are using your mobile phone to provide internet to your server(which is your laptop in your case), so here your mobile is acting as a router, and your mobile has provided local ip addresses to devices that connects to it. So what is happening is that when you enter your laptop's (server) ip address in client application for starting connection and your computer doesn't have any ip address in public(it has an ip address which is assigned by your mobile but it's not publically available and it's a local ip address which generally starts with 192.168........) so client app is unable to detect your server and servers which are connected to routers same is applied in their case.
So solution to this is, you enter your mobile's (which is providing internet to your server) ip address in your client application, and with any port forwarder application you do port forwarding to your server's(which is your laptop) ip address(and it's local ip address assigned by your phone/router to your laptop) and port(which you are using for communication with client), and there are many port forwader applications available on Google play store you can use anyone of them. So steps to start connection with client and server in your case are:
1: install and start any port forwader application in your phone from your mobiles store. 2: unable port forwarding (for every request which comes to your mobile's ip address) to your server's ip address (which is assigned by your mobile to your server). 3: Than enter your mobile's ip address in your client application.
And it will get connected to your server...

Failed to connect to local IP from Android application

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

How to connect to local ip address

I have absolutely no idea what I am doing wrong. About a month ago, I set up my router to work with a server/socket connection in Java. I just moved back to my apartment, and am using a different router with a different ip in a different area.
Connecting to localhost (as the default) with my ServerSocket, and then connecting to the ip I get from whatsmyip.org as the hostname for the client socket, shouldn't I be able to connect?
The server and client are running on the same computer, and if I switch the hostname of the client to localhost, the connection works perfectly. I have a port forwarding set up to my computer's ip address that the router gets for me (not from whatsmyip.org) to port 1640, which is what I was using back at my old place where it was working. What am I doing wrong here?
EDIT 1: I am using DynDNS.com to set up a hostname URL that links to my computer's IP, which I then have all of the clients connect to. The client program can be on any computer anywhere. Before I switch routers, this was working perfectly. I was using the Dynamic DNS feature of the router using my DynDNS account, which was set up on my old router, and my new one. So basically, I should just use my old router?
Some routers will not route the external IP while you are on the internal network. I had a router which was like this. Try connecting from an external location (have a friend try, connect to a remote server and connect back in, or use a device connected to 3G wireless etc).
But im not sure from your question if you actually want to connect from the outside. If you dont, there is no need to creating the port forward (in fact you are just making your server visible to the world unnecessarily). Use the local address of your machine (192.168.x.x / 10.1.1.* etc depending on your router) from any machine within your LAN.

Can't open web application made with Java EE on other local computers

I am trying to look the web application I made with Java EE. The server and database is up and running. It works on localhost:8080, but when I replace localhost with the local IP address all I get is a 404 error. Do I need to configure something?
On windows 7 open the firewall to allow incoming and outgoing traffic on port 8080. Then from the remote machine make sure that you can ping the server's ip address and then try to browse to the address.

UDP chat server-client not able to communicate on diff machines

I have written a UDP client server chat, I am able to communicate to server if both server and client are on same machine, but i am not able to do so when client is on some other machine using diff ip address. Is there any special setting to achieve this?
Regards,
Tara
Ping the other machine.
Disable firewall software on the other machine?
Make sure the other machine is listening on its actual IP address instead of localhost.

Categories

Resources