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.
Related
I created two Qt apps: one client and one server.
I use them to send some data for handle a remote device.
If I am in localhost I haven't issues about them, but when i search to connect them by internet i don't know how to find correct Ip server to connect Socket Client.
How i can find this ip node?
Is there a class to find It?
you cannot find it automatically, if this is what you're asking about.
In real life you would deploy your server on some publicly accessible host, give it a domain name (important part as your host can change the IP address at any time) and connect the client via the DNS domain.
However if you're just playing around and you want to show to the world that your app works, specifying the IP address of the server in your client code would be perfectly fine (assuming you're running both the server and the client in the same network).
In that case, if you're running mac/linux run the command ifconfig (or just ip depending on the distribution). On Windows you can run the command ipconfig. Both windows and linux will give you a similar output resembling this:
Pay attention to the network adapters. There can potentially be many of them. You may have some emulated adapters if you have docker or VMWare, you may have the wireless adapters if you have a WiFi card, and then the ethernet adapters if your computer can connect to the the internet with an ethernet cable. Each of these adapters specifies a different IPv4 address. You want to pick the one that is connected to the same network as your client. So for instance if both your server machine and your client running machine are connected to the same wifi, you pick the address from the Wireless LAN adapter
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.
I am developing a home automation application using IoT components. Most of these SOC's implement a web page for configuration and control, and I would like to be able to access these pages using the hostname vs. IP address.
Problem is some devices are accessible vis hostname and others are not. A port scan of my LAN shows some devices have host names and some don't. The ones with host names are accessible using the name, the others are not. All are WiFi connected using DHCP. The router is a generic WiFi router, with DHCP.
Since this is working on some devices I'm assuming that the infrastructure that makes this work is Ok, and the failure is on the part of the host when it registers itself on the network. So the question is, how does a host make it's name known to the network? Is it part of the WiFi connection protocol, DHCP, or what?
The objective is to fix the failing devices to properly register themselves on the network. I have source code for everything, so hopefully this is doable.
I have Raspberry Pi and a mobile app developed in ionic.It has to communicate over SocketIO and normal HTTP request. I can communicate if i know IP address and port no. But what if I'm using it over internet and my raspberry pi's IP address is changing dynamically due to DHCP. How do i connect to my raspberry Pi device. Is their a way to connect if I know MAC address of Rasspberry PI.
Short Answer: no
Slightly Longer:
MAC is only useful at Layer 2. So the minute you have a router between you and the device, you will no longer be able to see the MAC. If you control the Layer 2 network you can statically assign a DHCP address, or you can look at the logs and see what IP it was assigned, but if the device is connecting to networks you don't control and its address is changing, you will need a way for the Raspberry Pi to register where it currently lives. There are a variety of ways to do this, such as dynamic dns registration, or you could have it phone home to some sort of locator service that your app could then query, etc... But without extra software you are probably out of luck.
You should use a dynamic IP service like www.noip.com. They provide a free linux and/or windows client.
That way, when your public IP changes, you will still be able to connect.
I am trying to send data using the AsyncUDPSocket class. And I can send data using the iPhone simulator over the wire to another machine that is running a simple C-coded listening server. I can also receive data over the wire using a client connected to the simulator(server). However, when I tried the same over Wifi, using the simulator, I could only send data but not receive any data.
I read on another post, that unicast data makes this possible. How can I acheive this using AsyncUDPSocket?
Thanks,
Angelo.
Ok, I figured this out. A newbie kind of thing, really.
When I set my Mac network preferences to Ethernet, I get an IP for me to communicate. However, when I turn Airport(Wi-Fi for more newbies) ON, and ethernet cable disconnected, I checked my network preferences, and sure enough my IP address was a different one.
Spoke to a friend (an ace in networking) and the thing clicked immediately: On WiFi networks a DHCP server allocates an IP address. This IP address has to be reserved, at the very least, at the DHCP server. Since my IP was not reserved, I had to change the IP address, in my udp_client.c file, recompile and run the client to connect.
BTW, I can now communicate between my iPhone and my PC using my local WiFi (office) network.
For any who might face the same problem, do not be assured that the IP address of your mchine is the same, when you switch from LAN to Wifi, and use the device mostly for WiFi reated testing. :)