How do I connect to another network with a socket?

Asked

Viewed 397 times

-1

I have created some programs like a multiplayer ping pong game, chat and others, using socket. They all work perfectly and I can connect to other devices that are connected on the same network as me, but in all of them, I can’t connect to a different network.

I’ll let here the link to the repository of a program I recently created.

I searched deep, and first discovered that there are two types of ip (private and public). In the old days I couldn’t connect, probably because I was trying to use a private ip. So here’s my first question... How do I create the server with that my program using public ip ? I have tried using public ip and what I had done before was the following:

1 - I got my Public IP

2 - I opened the "Network and Sharing Center" > "Change adapter settings"

3 - I selected the network, clicked on "property" and selected "TCP/IP protocol version 4"

4 - I checked the option "Use the following IP address" and put there the public ip.

After that, I couldn’t connect anywhere, couldn’t open sites or anything like that (as I recall, he said it was a DNS glitch or something) and I had to restore the system settings because, undo the changes I made didn’t work. I did something wrong ? For me to use the public IP I need to talk to the provider or something like ?

I spoke to a friend of mine, and he recommended I try to use Hamachi. So when I created the server, I passed the hamachi ipv4 just like I do when I go to play Minecraft with a friend on LAN. However, even with hamachi I could not connect to another network.

Anyone there who is experienced in networking can tell me step by step what to do to connect somehow in another network using IP ? And already taking advantage, which is the correct Port number to use ? I’m using port number 60 or 80.

  • Somebody please help me!

  • 1

    You probably already found the problem, but when using some port, I advise you to use a high port number and check if there are no other applications using the same port, port 80 is used for http by default, your modem contains both ips, audience and private, your pc uses the internal network of your home that would be lan and who does the communication to the public network is your modem, already tried to redirect the ports in its configuration? research forward port

1 answer

1


You have to study networks. Understand about NAT - and then yes, after you understand what you’re doing, or use a product like Hamachi, or configure your router at home, so that some of the ports in your public IP are routed to your computer.

Here you can have some information to clarify:

http://blog.ccna.com.br/2009/04/19/entendendo-nat-network-address-translation/

Most internet providers in Brazil today leave instructions on how to access their router, so you can make this configuration.

But even so, due to the current V4 IP shortages, nothing guarantees that your provider will give you a real v4 IP up to your router - it may be that within the same provider you are behind another layer of NAT - if that’s the case, only something like Hamachi same.

Basically what happens: your provider gives you a public IP address, which is the address that the router from your home-use to access the internet. In the old models, from the time of the dial-up internet, and even in the first broadband, where there was only one home computer connected to the internet, this IP could also be the IP of the computer.

On your home router are local network (LAN) settings - which use private addresses - these are characterized by being addresses on some preset IP tracks of the type: "192.168.0.XXX" - any device within your home network that you try to manually set up for an IP from outside of that range will obviously not work. No use you put your computer to respond to the same IP that your router responds from your home to the internet - all devices: router, computers, mobile phones, smart-tvs, in your home can only exchange information directly using the range of local Ips - an IP out of this track has no way to be routed and will not be able to talk to anyone.

The internet "modem" in general also makes the times of wifi, and is the "gateway" - it can be accessed by a fixed address, and in general has a WEB interface for configuration. Just look at the "gateway" field of the network configuration (when it is working, with the default settings) of your computer to know what it is, but almost always the address is finished in "1" within the local network. For the above example, it would be "192.168.0.1" . In this case, point your browser to the address "http://192.168. 0.1" and you should see the WEB interface of your wifi router.

Check the documentation your provider left with you, or contact support to see your credentials for access to your modem/wifi. Until a few years ago, most providers left the standard equipment password. From one time to the next, each router has a login and custom passwords, which are usually posted on a label on the router itself.

This web interface will vary from device to device and from version to version - but all have the same functionality - among them the "routing": you can manually configure a port of your public IP, which is the router that "responds" to be forwarded (forwarded) to an internal local network IP and port. Ready - that’s all you have to do: your computer can responer on IP 192.168.0.11 port 8000 for a package that arrives on your IP p[iblico, port 80. = Just configure this routing on the router.

As I put above, this will work, unless you are behind another layer of NAT provider - ie: if your router IP is indeed public. Otherwise, I hope I have explained the concepts in other words so you can understand how to use Hamashi for what you want.

  • I understood more or less what you said, but still, it has helped a little to arrive at the solution. As you said, I will study networks to better understand all this, but is it possible for you to explain in the answer how Hamachi works so I can understand why I couldn’t connect with it? Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.