Socket connection not working with no-ip address - java

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.

Related

DatagramSocket with a public ip address

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.

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).

Using UDP to let clients know server's existance, is it possible?

I am very new to network programming, so this might be a no brainer. What I was wondering is, I know TCP requires the client to know the IP of the server. But since UDP is connectionless server, is it still required? I mean can I make my server broadcast it's IP address on a specific port ( not necessary in the same LAN , also over internet) and make the clients listen to that port for any incoming requests and find get the IP of the server once a request is received ?
You can try to send packages on specific port over the LAN. But for the Internet no.
Look into using ARP/RARP if that gives you what you need. Coming to your question
Mind you both TCP and UDP require IP addresses binding the ip address to a port is called a socket and there can be TCP and UDP with the same port no.
You can do this according to what you said but then the server needs to know the client addresses
Create a connection from server to client
Send IP address of server to client
Client send data using just received Server IP
to work around this you can use the broadcast address of the network and have the clients listen to it, just check what your broadcast address is.
What you are trying to do is similar to a DHCP server.

Sending a DatagramPacket from one PC to another over a LAN

I want Peer(s) to be able to send DatagramPackets over a WIFI LAN for the sole purpose of discovering other Peers. So, I have each Peer made up of a Client(Sending packets) and a Server (listening for packets).
I have only been able to get this to work by using IPConfig on each machine to get their respective IPv4 Address and then using that as a paramter for the creation of the DatagramPacket:-
InetAddress server = InetAddress.getByName("THE IPv4 ADDRESS OF THE PEER'S SERVER
RUNNING ON THE OTHER MACHINE");
DatagramPacket sendPacket = new DatagramPacket(outBuffer, outBuffer.length,
server, serverPort);
Am I using broadcast (for peer discovery) in the right way here because it seems pretty rubbish to me if I am? I was under the assumption I could have a client on machineA fire off a packet into the LAN abyss and the Server running on machineB would be listening to the entire LAN and detect the packet. At the moment all I'm doing is manually using IPConfig on the machine running the server and typing that address in the DatagramPacket on the machine running the client, which just seems pointless.
I can use multicast just fine but I think broadcast is more what I need for peer discovery.
Help appreciated.
That's not really broadcast, since you're giving the server's address, rather than the broadcast address (255.255.255.255, or whatever your local network broadcast address is (like 192.168.1.255, if your network segment is 192.168.1.0/24).
You also may consider that you could have a firewall blocking incoming UDP packets on your server port. You should look at the documentation for DatagramSocket/DatagramPacket to see if there's a magic incantation for binding the server socket properly, or sending the packet from the client properly.
[Edit: How to find the network broadcast]
The network broadcast address can be found once you know the network address, both of which you can tell from your IP and subnet mask. The subnet mask basically shows how much of the address is the network, and how much is the client. (subnet mask is often written as "netmask") An example:
IP: 192.168.1.101
Netmask: 255.255.255.0
Network Address (CIDR): 192.168.1.0/24
Broadcast Address: 192.168.1.255
or:
IP: 10.13.28.55
Netmask: 255.255.0.0
Network: 10.13.0.0/16
Broadcast Address: 10.13.255.255
So essentially, the network address has a bunch of zeroes at the end, and the broadcast address replaces them with ones.
IPv4 Addresses are 32-bit numbers (easiest to think of them as unsigned. If you do the bitwise-AND of your address and the netmask, you get the network address. If you bitwise-OR that with the bitwise-NOT of the netmask, you get the broadcast address (so (addr & netmask) | ~netmask) would get you the local broadcast).
255.255.255.255 (or 0xFFFFFFFF) is the global broadcast address. IP broadcasts don't cross network segments, so it's safe to send to it, though.
Use the broadcast address 255.255.255.255 for both server and client.

Categories

Resources