new to tcp/ip and network. I have some questions - networking

I am learning socket programming now and made a simple tcp/ip chatting application using c++. I can only talk to myself since it only works for localhost. Now I want to let people to connect to my device. I read many articles and come up with some questions and thoughts:
If I am using Ethernet (without firewall), would my external ip and internal ip be the same?
If I am using Ethernet (with firewall), the external ip would be masked by firewall and hence it would be different than the internal ip.
If I am using Wifi (my own router), the external ip would be different than the internal ip, and the internal ip would be like 192.168.x.xxx.
If I am using public wifi, such as apartment wifi and campus wifi, how can I open a port on the firewall? Talk to the IT staff?
I am not ready to rent a server atm. I want to make sure my chatting application can work on different devices. That's why I want to let my friends connect to my device and test it.
Please correct me if my concepts are wrong. Also, I will appreciate if you can recommend me any good sources for learning tcp/ip or networking.

If I am using Ethernet (without firewall), would my external ip and internal ip be the same?
If you aren't using any kind of router and just connect one machine directly to your incoming internet connection, maybe. Otherwise, the router will have to assign each machine an internal address that is distinct from the router's external address. Otherwise, how would it tell them apart?
If I am using Ethernet (with firewall), the external ip would be masked by firewall and hence it would be different than the internal ip.
It's not so much a firewall that does this but a NAT device. These are used when you have fewer valid external IP address (those are precious) than devices that need internet access. That makes the use of distinct internal and external addresses necessary.
If I am using Wifi (my own router), the external ip would be different than the internal ip, and the internal ip would be like 192.168.x.xxx.
That's a common way to do it. It's the same if you're using Ethernet. The issue is more internal devices than available external addresses.
If I am using public wifi, such as apartment wifi and campus wifi, how can I open a port on the firewall? Talk to the IT staff?
If they don't support UPnP (which does it automatically) you probably can't. But you could, in theory, try talking to their IT staff.

Related

Basic networking questions

I am trying to understand how exactly routing works:
if 2 computers are on the same network
if they are on different networks.
More specifically I am trying to understand this: Routing
I am also trying to understand the difference between
IP Address,
Net Address,
Mac Address.
From what I understand:
1) IP Address: is used when computers communicate on the internet only.
2) Net Address: is a local version of the IP address and each device on the network has a unique net address. It's used when devices on the same network want to communicate with each other.
3) Mac Address: is a globally unique address and no other computer in the world has the same Mac address. In reality this is not true because it can be changed. It's used when ???
When a computer wants to communicate with another on the same network, they use net address, right? If the computers are on different networks what exactly happens?
Question: Can someone please fix my mistakes if any and explain what I am missing?
Thank you very much.
There are many network types, but since the most used ones are Ethernet and IP networks (and you seem to be asking about them), I will answer shortly based on them.
IP addresses are always used. They may not be used for deciding who gets the packets directly, but they are the basis even in local networks, since it is an IP network. There can also be other network types that have their own mechanisms, but they are not that common.
In local Ethernet the machines ask via ARP protocol "who has this IP address?" and get a reply with a MAC address. After that they send and receive packets based on that MAC address. The packets still have the IP address information, otherwise the receiving machine wouldn't know what is the destination. Do note that the receiving machine might be a firewall or other middleware device, not the actual computer that has the address. Also a single machine and network card may have several IP addresses set up for it.
In IP networks the IP address is used for routing. All routing devices have a routing table that will tell where the packets should go. If it's a simple device, it usually has a local network and everything else goes via a default gw, which will know better what to do with the packets.
A home router will just push them to the operator, there another router will know what addresses go to their networks, others are pushed forward via another connection, until a bigger place is reached where there are inter-operator connections and they choose again the correct route. And then it goes to smaller and smaller pipes the other way around.

How to Find My Proper Ip Address to Connect to Another Computer Remotely

My friend wanted to connect to my computer using Remote Desktop Connection. But the problem is I am confused what my Ip address is.
My computer is connected to the internet via router via broadband internet network. My ip address is dynamic.
Here, my main purpose is not only the remote connection but also learning how dynamic ip connect to another pc.
I searched for ip address on Google. They show me an ip address. But I think it is not mine, it's related with the router or broadband network. I also find a WAN ip (it is different from that i found on google) on router settings. It did't work.
I used Team Viewer. It worked perfectly. But I want to do that manually because I am going to make a multiplayer game on GM8.
It will helpful if someone explain about ip and port forwarding.
Teamviewer is a great tool, but uses different techniques than what you plan to do. Teamviewer always uses an outgoing connection and use a mediator on the Internet to connect you and the other PC.
You should ask your Internet provider if he technically enables you to be reachable from the outside Internet. Often this is not possible at all, even if you configure your router the correct way.
When you ask this you can ask him if you have a static IP.
It seems you are not aware of basics of IP networking, so I'd strongly advise against trying this on your router as wrong settings would render it useless. But here's for your information how port forwarding and IP Address and dynamic DNS can be used to solve your problem.
Basically your ISP is likely to give you a router having an IP address. If this IP address is a global IP address, it is possible to connect to this IP from outside. How do you find out whether your IP address is global? Look for your WAN IP address setting. If it is in 10.x.x.x or 192.168.x.x range, it's unlikely to be global and in that case it might not be possible to connect to your computer from outside - without help of a third server (some kind of a registration server, where you connect and register your application). The Registration server would determine your globally visible IP address and then convey it to another Application who is interested in connecting to it. This is somewhat complicated to make it work (but if you intend to make a game - this is something you'd have to do regardless). This is mostly how software like TeamViewer would work.
If you have a global IP address - it means it can technically be reached from anywhere in the world. In that case you could use port forwarding to make things work for you. Port forwarding works basically as follows - You expose a certain port (on TCP) to external world - say 8000 and then you make a setting like following on your router.
<TCP>-<RouterIP>-8000 --> <TCP>-<Your LAN IP><Your application Port>
(You can find you lan ip using ipconfig on windows or ifconfig on Linux).
Now all connections coming to port 8000 would be directed to your application. You might want to do it on UDP as well and the protocol above would change. That is how you 'open' a few ports to be accessible from outside, configure them on your router and then run corresponding applications on your network.
There's another thing called dynamic DNS, where the IP address you use if it is dynamic (and global) can be registered with a Dynamic DNS server so that you don't have to know and remember the current WAN IP Address. But that can be for later.
Hope that helps.

Network communication without a centralized host. Is it possible?

I have a server and a few clients, software-wise, and I want the client to figure out the IP address of the server without actually referring to a specific database.
I had a misconception about UDP up until now that UDP only used the Port as a common identifier between servers and clients, but I was wrong apparently.
Requirement:
I want my server to broadcast a message to ALL devices on the network, once every 5 seconds or so.
That message will contain the IP of the server.
Software using such technique already:
A photo transfering app for iOS, called "Photo Transfer App" is really easy to use because it basically tells you to open the app on your Mac and on your iPhone, and then you press "Discover", and BAM! your devices have found each other.
But how?
How can my requirement be achieved?
EDIT
I googled a bit. Could server host on 255.255.255.255and clients connect to that address solve my problem?
According to this Wikipedia article, 255.255.255.255 is used for broadcasting.
Can someone confirm?
If you will use broadcast address (255.255.255.255) or network broadcast (like 192.168.1.255 for network 192.168.1.xxx or in the prefix notation 192.168.1.0/24). You will get essential limitation: your broadcast will NEVER leave that network. So all host inside the LAN will see your broadcast message but nobody else.
Multicast as mentioned by null is better because it can leave your network and pass through the IP routers. But this is feasible only by special network settings on that routers (and require multicast routing capability on that routers).
Another technology without such limitation can be use is dynamic DNS (server will register itself via DNS).
Multicast would be better than broadcast. See also: Bonjour, multicast DNS & SSDP.
More information on Bonjour is available here.

Same ip address for multiple devices?

I want to develop an Android app that connects with a Windows desktop application via TCP/IP.
However I have very little knowledge of networking and so please forgive me if this is a very basic doubt.
My Windows based laptop as well as Android phone are connected to the internet via the same WiFi router.
Now I checked the IP address for my laptop as well as phone using a website.
Both are same!
If both have the same IP address, then to achieve networking between these devices I will choose different set of port numbers.
Will this connection work?
Is the connection happening via the internet or just locally on my
router?
EDIT: After reading the answer from #Doon, I have broadened my question.
Let's say the local address of laptop is 192.168.1.10 and that of phone is 192.168.1.20.
If I code my application to use these IP addresses, it should work as it is a local network.
But what if I want my laptop to connect with another phone which is not connected to the WiFi router, rather by 3G network.
Then which IP address should be used for the laptop and the other phone?
Since I am not allowed to use any other server, I am going to use port forwarding i.e. the user will type in the IP address displayed on the other device. The connection could be initiated on either one of the devices.
If you could also show how to do this programmatically, it would be very helpful.
My Windows application is developed in C++ using Qt.
All of your devices are sharing 1 external or WAN IP address using NAPT (network address port translation). Internally on your LAN each device has its own address. So yes it will work but you are going to need to use internal addrss and the devices actual IP address not its perceived address via an external service.
As for the connection locally or via router that all depends on where you are connecting to. If both end points are on your lan or on the same Subnet then the router will not be involved. So in the average home network between your phone and desktop both connected to the same network say via wifi then they are most likely layer 2 adjacent (see the OSI 7 layer model for more info on layer 2 vs layer 3). But once they are not on the same network then routing will be involved and your router will be used. If the phone is connected to 3G or the cell data network and you want it to talk to your desktop on your home network you are going to need to deal with port forwarding on your router and other such fun things.
In regards to updates. Once you leave the local network it gets more complicated especially with IPv4 as address are running out so there is more and more use of nat or IPv6 with 6 to 4 gateways. Do you want the laptop to initiate connect to the phone or phone to the laptop? But normally you will need to iterate your address on your interfaces. Then connect with an external service to get your external IP address and compare and see if they are the same. if both endpoints are dynamically assigned you will need some sort of location mechanism could be dynamic DNS could be locator service etc.

Setting up local wireless server using WAMP

My goal is to have two laptops in a network. One is acting as a server, serving webpages to the other. The catch here is that neither is connected to the outside internet.
What I have done so far is setup WAMP on the server laptop, and it successfully serves web pages on localhost. Now I want to access these pages on the other laptop.
To do this, I had the server create an ad-hoc network and connected the other laptop to it, but I'm stuck - and I'm worried I'm not on the right track. I followed this tutorial but in the end I figured out that just explained how to spoof a text URL as an IP address, and not really what I was looking for.
So I guess I have two questions:
Is my method the best way to do this (with ad-hoc networks)? Is there some way to connect a laptop to a wireless router and have the laptop act as a server to another laptop?
If my WAMP and ad-hoc network should work, how do I connect other laptops to my server through the ad-hoc network?
Thanks!
I would suggest the first option: get a wifi router. Then you can assign static IP adresses from the routers private network or use DHCP server on the router. Hopefully you will have an option to reserve IP adresses on DHCP server so you dont have to check every time what IP adress the laptop acting as a server got. You use this address to access your web server. Also, you can use this router later as a gateway to the internet if you want.
In ad hoc mode you will probably get an address from 169.254.0.0/16 link-local scope, and you can check it by running ipconfig as #Robadob already suggested.
On your hosting laptop open cmd and call ipconfig look for the internal IP address on the network interface your hosting the ad-hoc network.
Enter that IP address into the browser on your client laptops web browser instead of localhost.
If that doesn't work, try other ip addresses listed by ipconfig (incase you used the wrong) and then check the properties of your ad-hoc network, windows firewall and any other firewall software to disable anything that might be blocking it.
An ad-hoc network is suitable option for what your doing, most people would probably use a switch or router though, however that requires hardware you probably don't have.

Resources