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.
Related
Im making a client/server app just for learning purposes, and i want my Client to connect the server (which is running in my pc) from another pc.
Right now im trying to use the server's pc public ip (which I got with whatsmyip.org) in the Client socket: Socket sock = new Socket(HOST, PORT); where host is the public ip of the server's pc.
When I was testing it with localhost and the client running in the same pc, the connection worked.
I already oppened the port im using in the Server pc and added firewall rules, including router's firewall. So any of my firewalls should be blocking the connection to the port im using.
I read in another question this (it was an example): "Your Server PC is in New York with an IP 192.168.1.121, that is behind a router with internal IP 192.168.1.1 and public IP 40.20.26.63. You will need to make sure that you go into the router and forward port 8084 (TCP) to internal address 192.168.1.121 (the internal Server PC)." How can I do that? I know the public IP and the internal IP of the server, but I dont know what IP I need to type in the Client Socket.
Thanks in advance.
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...
"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).
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.
I have fully developed a chat room for multiple clients with multi-threaded server which does the job, however only on my local machine. I want to go beyond this, and make this chat room to be working over the internet. So far I have made the port forwarding on my router for TCP protocol to route to my local IP address, however this didn't solve the problem and I still can't connect the client, even on my own local network. What other steps should I follow to get my chat room working on my own local network and then the internet?
try disable (windows) firewall ?
So my friend the basic rule for make anything to work over internet is to do Port forwarding or in simple way you can say that to open your server for the public network. For that you need to make sure that the routing path is complete from internet machines to your desktop. For this to work you need to open the port for which you need to access your machine from firewall settings, and also ensuring that trafic is routed from your public IP address to the server's IP as your server will be private under some router or ISP.
Way to do that:
You need to configure your home network i.e router setting. So in your router, configure the port you want the communication to happen(say port 5443).
In your router, configure a port-forward for the port 5443 to the internal IP address of your actual server, also to port 5443.
Reference: https://www.noip.com/support/knowledgebase/general-port-forwarding-guide/
On your server(your Desktop Machine) ensure that your firewall settings for port 5443 is on and set to allow rather than block.