I wrote a chat application, client+server using sockets. The problem is that I have to make it comunicate over internet and it's working only over LAN. I disabled my firewall, I verified my address to be public BUT I cannot make it work over internet. What's the problem? If I connect the client to my local IP, ok. If I try to connect it to my public or someone else computer my public IP, it's not working. "Connection is refuzed" I need this so much! Please help if you can! My application should send files over internet between the two computers. I tried all these days...
There is really no difference between a LAN and a WAN in this regard. Two computers simply talk via a socket, that are connected using IP addresses as targets. So, your chat program should work regardless of it being a local network versus the internet.
So... what is the difference? Generally, no one places a computer directly on the internet anymore. Instead, they use a router, which creates a private network, and all the computers in the house are behind it. This means that no one on the internet sees your computer -- they only see the router. This is used to protect your home computer from bad people on the internet. So... how to do this?
If both computers are directly on the internet, then it should work unchanged.
If one computer is on the internet, and the other is behind a router, then the computer behind the router must be the one that initiates all the connections -- as the computer directly on the internet can't see the computer behind the router.
If both computers are on the router, then it gets a bit harder. First, you need to configure your router to port forward to your computer behind the router -- basically, if someone on the internet tries to connect to your router at a particular port, it will be routed to your computer at the same or different port. Second, from the other computer, you can try to connect to the first computer by connecting to the first computer's router -- which will be forwarded.
Thanks for reply, Henry.
My computer which would run the server application is behind a router (ASUS). I don't know how to forward the port. The other computer (a friend) runs the client and I don't think he has a router... but however I will take your advices.
I must add that I tried to run the server and client both on my computer and connect the client to my public address. If the port was forwarded the connection should be entablished?
Now as you know exactly the situation can you tell me how to forward the port? And should I disable my antivirus and firewall or add the forwarded port as "trusted"?
claudiu teodorescu wrote:Now as you know exactly the situation can you tell me how to forward the port?
This completely depends on your router. You need to log into your router to configure it. And the administration screens are different for different products. To connect to the router though, is generally done by using a browser to log in.
Also, if you are using DHCP, you may also want to configure your server with a static IP address -- depending if the port forwarding menu, ask for an IP address or not (some are smart enough to need only a mac address).
claudiu teodorescu wrote:And should I disable my antivirus and firewall or add the forwarded port as "trusted"?
Well, if you are going to go through the trouble of port forwarding at the router, only to have your server block the connection, that kinda defeats the purpose, doesn't it?
I made my ip static. And tried to forward the port.. see the images... I don't know if I made it well... all I know is I cannot connect the client to server yet. It's working in LAN. Thanks for interest in helping me
hey I've been working on a similar program. I configured my router to forward to my computer and the program connects through the router's ip address, which works when i run it at home but my friend who is not behind a router could not connect, any tips?
Yeap... I could connect by forwarding the port on my router.... but when I try from a friend... (with no router) I cannot connect to him (he would be the server who initiates the connection). Don't know why... try tell your friend so close all the firewalls and try again...
claudiu teodorescu wrote:try tell your friend so close all the firewalls and try again...
Then tell him to smack you in the head for suggesting a solution that ends up with his PC being hacked and flooded in viruses.
If you think I'm kidding, sadly not. If you connect an unprotected Windows machine directly to the Internet that PC is bound to be hacked and/or infected within half an hour, without even doing anything like opening a web browser. The cause is that many of the Windows services (like RPC, NetBIOS, etc) are enabled, unsafe and easily target / infected. Viruses like Blaster can and will infect a PC within mere minutes.
He should check his firewall though, and see if it is blocking any unknown traffic. He should only allow what needs to be allowed.