How to connect to a server using an external ip (Java)? - java

I'm doing a project, I have a server, a client (C #), a client (Android java). I can connect to the server on the local network and use an external ip from the client C #, but from the Java client I can connect only by Wifi. The server on the router port forwarding, I have a static ip address. Help please what's the problem?

From the info you provided, there is nothing wrong.
For your C# client, you can connect it from local network (i assume 192.168.x.x)
and
For your java client, using wifi means local network (also i assumed 192.168.x.x)
so it means that it works well with local network.
So now the main problem is, is your server really online to internet
Please check the following:
Is your server accessible via any api testing tools, such as RESTFUL AND SOAPUI using external ip address.
Is you android client really online when not using a local network, or you can access it through external ip address.

Related

Public to Local IP Communication

I have created project which has two components as Desktop client and web.
web server is communicating to the my another program which i run as client on other systems.
After connecting those clients communication is happening in network as all IP's within network are reachable.
However, when i deployed web app on public IP now i am not able to connect the clients as the local IP's of those clients are not reachable by server.
How can i achieve this communication between local IP to public and vice versa?
There are multiple ways to achieve this.
Anyways, if you want the service to be reachable publically then you´ll probalby want to forward the Port to the machine running the service.
Also, make sure the Firewall allows connections to this port.
Since you´re talking about Web-Apps it´s probably HTTP, Port 80 TCP, or HTTPS, the encrypted version of HTTP running on port 443 TCP.
To explain it, your ISP gives you one public IP address.
Since you probably have multiple devices using internet, they all appear in the internet as the one IP address your provider gave you.
Whenever you send something out your router will remember where you tried to connect and if a response comes in your router knows which device to send the response to.
Now, since you want someone to connect to you, there was no request so your router does not know where to put the packet and simply blocks it.
In most routers you can configure something usually called NAT or Port Forwarding. You simply specify that communication on Port 80 or 443 should be routed to the internal IP. It has one of the following formats:
192.168.0.1 - 192.168.255.254
172.16.XXX.XXX - 172.31.255.254
10.0.0.0 – 10.255.255.254

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.

How to "deploy" a server so that it can be reached over the internet?

I recently developed an Android application with which the Android device can communicate with another Android device running the application.
The communication works over sockets, therefore I developed a server which i run on my computer.
Here is my problem:
The communication between the devices over the Server running on my PC works fine, as long as all devices as well as the PC are in the same LAN (connected over the same Router for example).
Now I want to get the server online, so that the Android devices can connect to the "online" server and communicate with each other over the server from anywhere.
I simply have no idea of how to get the server online and running. How can I do that?
The main issue is, that I know about Client/Server communication locally, but have no experience in the "online" sector.
It is more a network problem than a programming one. Your server open a socket and therefore is available to anyone able to reach that socket.
You have to do a redirection on your router. The problem is that your machine doesn't have a public IP, only your router has one. So when your router receive a packet on port 21 for example, it doesn't know what to do with it. You have to configure it to say "the port 21 has to redirected to the local IP XXX"
Also the public IP of your modem/router can change, depending on your ISP. If your have a fixed IP, it won't change, otherwise you will have to install a software like dyndns to have a domain name associated with your IP.

Java TCP/IP Socket internet connection problems

Im using TCP/IP sockets in java to try and create a client-server application. The program works fine when run locally and also over the local area network, but when I use the internet IP address the clients connection is refused.
I used this website to get my IP address and have added a firewall entry to unblock the port im using (port 4445).
I am almost certain the problem lies in some sort of security measure that is blocking the port. Does it matter that I'm running the client and server on the same PC but using the IP address from the previously mentioned website?
If I could get a list of ways to test the port is in fact open, or a list of things to try in order to get my program running, that would be great!
That website may very likely give you the IP address of the gateway through which your PC is connecting to the internet, and if the gateway is out of your control (which is most of the cases as far as I know) there's nothing you can do to use that IP address to test your program. Here's some advice:
Try http://aws.amazon.com, once registered you have one-year free access to a micro-server (which can be accessed publicly through DNS/Elastic IP.)
If your PC have a public IP address, you don't need that website to find out what it is. Just check your network adapter control panel.
Where is the server has been located? If your server is located in some commercial hosting, there is possibility that the ports you use are blocked. Also if you use modem with router or just router in your local network you should check nat table.

Accessing a Java Web Application via Mobile

I have a basic web application written in Java, running on a tomcat on my localhost. Currently it's just a simple application with a single servlet to which I access from my browser.
I want to write a mobile android application which will be the client of my Java web application. I want the servlet to write to a DB and do some logic, but to access it from a mobile app.
Currently I don't have any domain registered.
How can I expose my Java web app so that in my development environment I would be able to access it via my mobile device? Meaning, currently it runs locally on my PC and I access from the browser (on localhost). I want to access it from a different device (mobile) - how can it be done in my home LAN?
Thanks.
If the web app is hosted on your local server, your mobile will need to be able to access the IP address (ie: 192.168.1.100) and port (ie: 8080) that is hosting the app.
There are several ways to allow your mobile to communicate to your desktop:
Direct connection via USB or Bluetooth.
Wireless connection on your LAN - if your mobile can connect
wirelessly to your home LAN, you should be able to access your web
app (your desktop's firewall may have to open up your web port)
External access. This requires opening up your home network to allow
access to your desktop's web port. Also your internet router would
have to be configured to allow access and likely do a NAT
translation. Note that in this scenario, anybody can access your web
app so be very careful. You would also need to use your external IP
address instead of your internal LAN address.
A domain is only required to allow the use of a name (http://www.example.com) instead of your IP address.
For testing, if your mobile device is on the same LAN as your server, just use the servers ip address on the LAN. Give the server a static ip address and your sorted.
For the next stage of testing, you'd need to expose your pc to access via the Internet. You'd usually do this by configuring your NAT settings on your home router. You should be able to google this.
Then your mobile device can use 3G and should talk to the server via your ISP ip address. This will hit your router and the NAT routing will forward it to your server machine on your LAN.
If you need any clarification, just ask !

Categories

Resources