Fundamental Networking Understanding - node.js

treading some unfamiliar waters. I'm currently writing a game client in Unity/C# and a game server in NodeJS. I've been doing a lot of Googling to try and get some answers, but there are some fundamentals I'm definitely not understanding. From what I understand, there are three relevant IP addresses here: my external IP address, 127.0.0.1, and 0.0.0.0. I've tried every permutation of these for client and server (with or without common sense), and the only combination that works is 127.0.0.1 x 127.0.0.1. I assume ultimately that the server will need to be on 0.0.0.0, but currently Unity errors out because the socket is already in use by the server- I assume that this would not be an issue with remote hosting.
My questions are:
Is it possible to host this on my home computer without socket overlap? Virtual machine?
Why does 127.0.0.1 x 127.0.0.1 work? Does the client convert it to another local address under the hood? I assume that they would both be UDP/127.0.0.1/port sockets.
I'd like to put the multiplayer into this game as soon as possible. Thank you!

Yes, it is possible, with virtual hosts, virtual machines. If you are working in windows, take a look at XAMPP or WAMPP if you are in a Mac.
This is a little big larger:
127.0.0.1 is the localhost (basically, yourself) also known as loopback adress.
And 0.0.0.0 is a non-routable meta-adress. Basically it serves to designate invalid targets, it's like a placeholder for "unknown" adresses. Serves to designate invalid targets doesn't means that is an invalid adress!
In your context, if you're using the 0.0.0.0 as a server it means "all IPv4 adresses on the local machine". If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host listens on 0.0.0.0, it will be reachable at both of those IPs.
This tutorial from Tom Weiland really helps me to learn about on-line programming in Unity, check it out: https://www.youtube.com/watch?v=uh8XaC0Y5MA

Related

How to find the interface offering the route to a specific IP in Python3?

On a Windows machine there are different network interfaces available. One of these interfaces is the TAP interface connected to a VPN-server, with a specific IP (e.g. 10.25.1.9). To reach the host 10.2.1.1 the route leads through this interface.
I want to start a local python server program and bind it to this interface, so I need to know the IP address to bind to. Since this local server program shall be installed on several machines from which I don't know the IP addresses, I want to find this IP automagically.
It can be that there are several VPN connections installed on the machine, so neither a IP address prefix is unambiguous nor the interface name can safely assumed to be unique.
The only safe thing I know about the interface is the fact that through it the host 10.2.1.1 can be reached (probably I will test some simple service on that host to be sure that this is the right one).
I had a look at netifaces but it does not offer this. I also had a look at PyRoute2 but this is not available on Windows machines.
So, my question remains: how can I find out which interface the route to my VPN base host 10.2.1.1 leads through, so I can take this IP to bind to?
Provided that there is any known service to connect to on the remote host, use socket.getsockname() to find out which local IP is used for connecting:
import socket
# connect to known destination, e.g. via UDP port 80
test_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
test_sock.connect(("10.2.1.1", 80))
# check which local IP was used to connect
with test_sock:
private_ip, *_ = test_sock.getsockname()

How to expose tornado websocket from local machine

I have built a d3.js dashboard that ties into a tornado websocket. Everything works perfectly locally. I now would like to have the ability to share the websocket with a few friends, nothing production. Is there a way to do this without a big deployment on Heroku or other similar service? I've googled and can't seem to find an answer. Thanks
Not specific to Tornado. This is more of a networking question.
What you want to do is:
Run your server on your computer.
Connect to the internet.
Note down your public IP address.
Give your IP address to your friends.
Certain things you need to take care of:
Run your server on a higher, non-standard port (e.g. 8000 would be good) because ISPs block traffic to port 80 and other standard ports.
The IP address assigned to you by your ISP will most probably be dynamic. That mean, every time you diconnect and reconnect to the internet, your IP address will change.
Turn off your computer's firewall to let in the traffic at whichever port your server is running.
Finally, you'll need to configure port forwarding on your router. What that means is all the incoming HTTP requests will arrive at your router at your public IP address. But your computer where you'll be running your server will have an internal IP address assigned by your router. So, you'll need to forward incoming requests to your computer's internal IP.

Linux : IP address to service?

I have an app running as a daemon on a linux box (Red Hat). The purpose of the app is to act as a registrar of sorts -- another device can connect to this host machine, and register (this is me, I am here -- this kind of thing). There is more than one IP address for this machine.
How do I connect/send/forward incoming connections (i.e., the registration data) to my daemon? That is, when the device wants to register and connects to my IP address, how do I direct the traffic to my process/daemon?
Thank you very much for all your help!
:bp:
Hi you may need to give a little more info.
What it sounds like you want to do is listen on a tcp port with your daemon. There are different ways to do this in different languages.
Another thing to watch out for are the reserved port ranges. Some ports can only be used by users with elevated privileges. See here http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers TCP and UDP port ranges, They dynamic range is free to use as long as there is nothing else on that port.
What language are you using? In Perl This, is how you listen. And I could list off other tutorials for other languages, but there is not much point.
In reponse to the comment, I think this stackoverflow question answers the question.

Troubles accessing the VirtualHost on a local net

Hi I have a Huawei ADSL modem with a dynamic IP. I set up a dynamic dns with freedns and I can easily access my Virtual host on apache from outside my private network, from internet.
So trying to access it from a local network I get a modems login page.
I have the rule in my modems NAT to connect port 80 to my server but it seems it doesnt work from internal net.
My server hosting the virtual host is 192.168.0.1 , the modem has the 192.168.0.254 address.
I tried to put my external domain name into the /etc/hosts file, but if I do that then asterisk server gets confused.
What could be the cause of the problem ? And what would be the best solution to this problem ?
Should I set up a caching DNS on the private side of the net ?
Hugger is half right... Its because your router is blocking loopbacks. The easiest way around this is to edit the hosts file (See the Wiki page) on the computer that is behind the network to see the local IP of the computer as the virtual host your going for. For example if your server is on 192.168.0.1 and the virtual hostname is www.imrad.com then insert
192.168.0.1 www.imrad.com
into your hosts file. If your computer leaves the local network (like a laptop you take to work) and joins a network not behind your router you need to comment out the line in the hosts file.
well actually to access that you must find the local ip address of the server by going into command line/prompt and typing ipconfig /all then you will find ipv4 address. Take note of that.
Go to another computer and your that ip and it will show.
The reason that was happening is because the router/modem knows you are in its network so it will think you ar trying to go top the login page of it. That happens to me too.

xampp server (How to get up and running)

I've been developing locally on a little ubuntu netbook with xampp for about 7 months. Two weeks ago I got a computer I'd like to use as a server. I've installed the latest Ubuntu distribution and xampp, moved all my files over, and forwarded port 80. I've also got a domain name from dyndns.com which is being updated by a client which runs in my router (a Netgear WGR6154 v8).
Now, when I try to access my server by typing in the address I got from dyndns.com the browser loads until it timesout. I can access everything locally using localhost as the address so I believe xampp is running, just unable to connect with the internet.
In order to be able to view my files over the internet what should I do next?
Thanks to all in advance...
[I'm starting a bounty for the first person to help me get my files successfully online]
You have a combination of issues here, and that is something of a problem. Each issue is complex in an of itself. Here is what I would recommend to get you going for certain.
First verify that you can surf the web from your server. This will confirm that you have a working ethernet interface.
Step 1 make sure that XAMPP, and your files are viewable from your home network. I assume you are using something like 192.168.1.X for your network and perhaps your server is 192.168.1.10
Go to another computer in your house and type http://192.168.1.10/ and see if you can see your files. If you can then you know that the server is properly configured and XAMPP is working.
Then add an entry to your hosts file to resolve yourdnsrecord.com (or whatever your dyndns record is) to your private ip address. Then when you type yourdnsrecord.com into a browser from that computer you should still get your files. This will rule out your server being improperly configured to listen for that domain name.
Next you need to test to see if there is a firewall problem. To simplify this, first remove your home router from the equation. Instead, place your new server directly onto your internet connection. (assuming you can). This way, you do not need to have NAT or firewalls properly configured. Your dyndns name should map to a public IP and your server should then have that IP and be connected directly to the Internet. If you have your server directly connected, and the command ifconfig from the root prompt returns the same public IP address that your dynamic dns record is point to, then it should work.
It will make your life easier if you have an iphone or some other way to test how your network is seen from the Internet.
If your public IP as shown by ifconfig is different than the IP record in your dyndns account, then your dynamic dns update script is broken. manually set the IP, and see if things work.
It is very possible that this will not work. Some ISPs firewall port 80 preventing their subscribers from hosting servers. Once you have your server directly connected to the internet you can test this (even if your dns is not working) by using the public IP address. As root, type ifconfig from the command prompt to get your public ip address. Then type the command tcpdump -i eth? port 80 from the root prompt. eth? needs to be the same interface that you saw had a public IP address from the ifconfig command. usually this is eth0 but it might be wire0 or something like that.
This command will show you all traffic coming on port 80 to your server.
From an iphone (or whatever second Internet connection you have) browse to the IP address that you got from your ifconfig command. If you see something on your server (and it is directly connected to your ISP) then your ISP is not firewalling you.
If you can get to your server, when it is directly connected to the Internet, either by IP address or by DynDNS address, then your ISP is OK and it is time to debug your firewall.
Two things need to work for your firewall to be configured NAT, where the public address that your router gets from your ISP is converted into your private network and a firewall rule which permits that traffic. If you get this far, then you know your firewall is the problem and then it is just a matter of getting its configuration correct. There are far to many home routers to document here, but you usually can find how-to instructions for your router for this task from the manufacturers website (usually it is part of the manual)
If you follow these instructions exactly you will get your system working. Make comments on the process and I will be happy to modify this to make it clearer.
HTH,
-FT
You should make sure your xampp is not listening to only the localhost.
to do so edit your apache configuration file and check and search for Listen directive
you should be able to know also by analysing the output of netstat -a.
After that make sure your router is forwarding properly, using tcpdump would help.
drop me a comment if you need more help.
Cheers

Resources