DatagramSocket with a public ip address - java

hello everyone i'm making an application that uses DatagramSocket to transmit data between Pc and android Phone it works when i use a local ip Address but when i use ddns from no-ip or my public ip address it didn't i work i get this error message
DatagramSocket serverSocket = new DatagramSocket(port,InetAddress.getByName("XXXXX.ddns.net"));
i got this error message :
java.net.BindException: Cannot assign requested address: Cannot bind
plz help me how can i establish a connection between two machines using no-ip ddns instead of my local ip address

You can only bind an addresses that are configured on network interfaces on the device you use. I don't know your home network setup but most likely your public IP address is configured on the router/modem you use to connect to the internet so this simply will not work.
Your router may have port forwarding feature where it sends packets sent to a specific port to a specific IP address in your home network. You would have to configure a static IP address on the device and set up port forwarding to that address.

Related

connecting to a remote java application

I have to build a server/client chat room in java as a school project, and I want to know if I can connect to that server from the world network (not local network) using the IP address and ports (I wanted to host it but I realized too late that I should have built a web app not a desktop one). My app is using Transmission Content Protocol(TCP) sockets. I have tried to connect to the app by using the public IP and the port that I have opened in firewall. I can post the code if needed. Thanks in advance
If your networks firewall settings let you do it, of course you can connect.
Now, your computer has an internal ip address, which is like 192.168.xxx.xxx and your router has an external ip address which is unique.
Set up your router to forward connections. Steps to do it may change for each router but the point is to forward all connections coming to this router with a port number you have declared, to a internal ip address and a port number.
In your client side, your connection statement will have your external ip adress and the port number you have written in your router settings. In your server side, it will listen your internal ip address and the port number your router forwards to.
To be clear;
Client ---"xx.xx.xx.xx:9999"---> Router ---"192.168.xx.xx:8888"---> Server
As you see above, the router forwards all the connections coming to 9999. port, to 192.168.xx.xx address and 8888. port.

How to specify full ip address to the local server?

"Full ip" means global ip(I have a static) + local ip(192.168.0.xxx - address in my local network).
I wrote simple Server and Client application using java.net.ServerSocket and java.net.Socket relatively.
On the localhost it working good. But I'm interesting in running server app on the computer in my local network(router) and connecting to it from everywhere using Client app.
Connection is established as follows:
Socket socket = new Socket(IP, PORT);
I tried my absolute static ip(but it's router ip), router ip + local ip(192.168.0.100) it's all not working.
How can I specify the full path to my "server" in router local network?
I think you misunderstood IP addresses.
Any IP address is just a SINGLE IP address. There is no such thing as a "relative" IP address, like you have a relative path in a file system.
Suppose you have an externally-visible router IP of, say 136.23.75.30. You then have a local subnet of 192.168.x.y, where your own host has an address of 192.168.1.100 and your router has address of 192.168.1.1 .
In that situation, when you connect to your host from inside your subnet, you can specify the host's address on the subnet, 192.168.1.100 .
However, when you connect from the Internet at-large, the only IP you can connect to is you router's external IP, as provided by your ISP. In our example it's 136.23.75.30 . Any attempt to connect to 192.168.1.100 from any location outside of your own subnet will go to a wrong host or nowhere at all.
How can you accomplish what you need? The secret is in your router's configuration. You need to set the router up for port forwarding. Basically, your router will take the incoming connection on certain port (let's say 8888) and turn that connection into the connection to your host, 192, 168.1.100 on, for example, the same port, 8888.
In other words, the outside world thinks that it connects to 136.23.75.30, while in reality the router makes sure that 192.168.1.100 is responding.
Assuming this is a home setup, you need to get to you router's admin screen. You can do it by putting "http://192.168.1.1" into your browser's address bar. After providing suitable authentication (usually printed on the router's back) you need to find some sort of advanced setup tab, and look for "Port Forwarding". There you usually enter the target address, 192.168.1.100, and the source and target port (let's say both are 8888).

Public ip socket networking

I have a server object and client object that can connect and communicate with each other.
The client connects using the servers private IP address.
But I would like to be able to use public IP addresses to be able to communicate over the internet.
I get the public ip address using a url www.whatsmyip.com as a url.
I paste this public ip address where needed, but the client is unable to seemingly find the server using the public IP address
It doesn't have anything to do with code, as long as the server is binding to INADDR_ANY. It has to do with correct port forwarding at the server-side firewall.

Socket connection not working with no-ip address

I am having an issue with my socket connection. When I replace my no-ip address with "localhost" it works fine, but as soon as I put in my no-ip address, it cannot connect. I have forwarded the port from my router (port 12345 TCP and UDP forwarded to my local IP address 192.168.1.116). I don't understand why it would work with "localhost" but not with "myaddress.no-ip.org". It was of my understanding all you had to do was forward the port on your router to your local IP address.
You can't forward your internal IP address. A 192.168.x.x address is only usable on your internal network. You need to forward you external address. http://whatismyipaddress.com/
OK, here is the most probable solution to the problem. The Modem that I have from Time Warner (RoadRunner) has a built in modem. I have to get them to bridge the connection so it passes through the router. My router was looking for something to come in on port 12345 so it could direct it to my computer. The problem was that TWCs router wasn't forwarding it to my router. After bridging the connection, it should just pass through the modem to my router.

java.net.BindException when creating datagram socket in Android on Mac

I am creating one datagram socket in my application like below:
DatagramSocket socket = new DatagramSocket(60000,
InetAddrByName("192.168.1.72"));
This datagram constructor returns with exception
java.net.BindException: The requested address could not be bound.
I have added the android.permission.INTERNET to my manifest file. I am using iMac and Eclipse 3.4.2. I checked that port 60000 is free. Also 192.168.1.72 is my ip address. So what could be the problem?
from the dev site
Referring to localhost from the emulated environment
If you need to refer to your host computer's localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer's loopback interface. From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface.
What do mean by "my ip address".
This is one of the addresses you see when you enumerate the NetworkInterface instances ON THE device?

Categories

Resources