The short answer is:
Yes. It’s perfectly possible to make that happen. You don’t need any specific application like Apache. All you need is a router, know your Public IP and redirect, on your router, the packets coming from the Public IP on a specific TCP port to the internal IP of the computer running the Chat server. This port redirection (Port Forward) is critical, unless the chat is running on the router itself.
The long answer is:
On the internal network, if computers are on the same subnet, it is easy to get them to communicate. This is your current case.
However, when you want to communicate with a computer that is inside your home, from a computer that is outside your home, things get a little more complicated. The fundamental question is that to communicate this way, you need to know your Public IP, IE, the IP that the provider provides you for you to be able to surf the Internet from your home.
It is very common for the provider to also provide you with a router, as this allows several devices that are connected on your home network, whether by wi-fi or wire, to surf the Internet simultaneously. In addition to knowing your Public IP, you need to know which TCP port your chat is listening to (this you already know).
For you to understand better, let’s call the computer outside your home from EXT and the computer inside your home INT. The INT is connected to your home router, called here ROT.
EXT - External Computer - Public IP hypothetical: 200.123.12.21
ROT - Router (or gateway) connecting INT on the Internet. IP Public hypothetical: 179.79.12.12. Internal IP: 192.168.1.1
INT - Internal Computer - Hypothetical Internal IP: 192.168.1.23. Hypothetical TCP port that the chat server is listening to: 3131
Basically it works like this:
Goal: EXT want to connect to a chat service running on the machine INT who is in the house of @Pascalstarting;
- EXT need to know the Public IP of ROT.
- EXT also need to know the port that the chat service is listening to.
- EXT then, with the chat client, it connects at 179.79.12.12:3131.
- The package sent by EXT go through several routers until arriving in ROT.
- The moment that package arrives in ROT it is redirected to port 3131 on Internal IP 192.168.1.23 (the IP of the INT)
- INT then receives this package, processes and responds. (Like INT responds and that package arrives again on EXT leave for you to search.)
That’s basically it. There are interesting questions to consider, such as security and availability as the other answer said. Another very important issue is that providers change their Public IP constantly, so having a DDNS (Dynamic DNS or Dynamic DNS) service configured on the router is critical.
As a form of learning, I strongly recommend that you try this, because much will be learned in the process.
As a curiosity, I have a scheme of this kind in my house. I can turn a computer on remotely, work and then turn it off, also remotely. However, as I am boring with security, I use SSH Port Forward. My router is a TP-Link N750, running Openwrt (Linux), so I can have SSH and other services that allow me to manage my home network securely.
Who gave -1, could explain the pq? +1, this question will help many people.
– user6406