Socket programming: How a socket client may discover server IP address inside LAN? - c++

Scope:
OS: MACOS, Windows;
Language: C++Boost library;
Description:
LAN has N computers with MacOS and Windows operating systems, where N ≈ 10. The IP addresses of the computer are not static and assigned by the network. On one of these computers (machine S) a socket server application is running. And on another machine (machine C) a client socket application is running. This is not a static setup, and next time it might be different computers with different IP addresses.
Update:
a server machine -- is a slave. A client machine is a master. A user can install client software in any computer in LAN, and server software in any other computer in LAN. Server take responsibility for the calculations which takes a lot of resources and just send a result to a client. So, the main idea is: a user of a master computer should not provide a server IP address, but the client soft should be able to discover it by itself.
Task: Client socket application does not know Server application IP address, and should be able to discover it.
Solution should be a cross-platform one (Boost C++)
Please suggest the best practices.
My best guess was: retrieve all the IP addresses of connected devices and socket->send_async_to them. And if I get answer in handle_receive callback -- this is a server app. But I did not find a way how to get all the IP addresses of LAN devices.
Thank you in advance for your suggestions and ideas.

use UDP to send request to all the computers in the network.Write a thread in server to respond udp request. then you can get response from the server and get the socket ip.

Related

Find DBus server by broadcast (or otherwise)

In my Qt application I am using a peer to peer DBus connection. Server runs on computer A, client on B, connected via DBus TCP/IP connection. Works fine.
I wonder if I can somehow find out whether the server is running and what its IP address is? So far I need to provide the correct address/port in the client.
Both, server and client run in a local network. Of course, I can use a trial and error approach and ping all machines in my network. Is there something better, something like a broadcast asking for the server, and the server responding appropriately? Is Qt providing something for this?

how to get IP address of a computers that is directly connected to my PC

I'm trying to write a function that can get me the IP adress (and the name of the device as bonus) of devices that are in my network, the network is gonna be a direct connection between two computers using Ethernet cable or creating an access point (using wi-fi)
I tried to search about how to do it but it seems like I need to listen to the network or something which seems to be difficult.
hope you can guide me to what I should do or read to get started.
Note: I'm using Windows on both computers.
Edited:
P.S: I need the IP Address so I can send a message to the other computer using winsock in a Client/Server program I wrote.
can't I make the server send its IP to the client or the opposite ?
If your software is running on both machines, you can have one (or both) machines send out a particular broadcast (or, if you prefer, multicast) UDP packet on a specific port. Your program should also be listening on that same port. When it receives that packet (using recvfrom()), recvfrom()'s fifth argument will contain the IP address of the machine that sent the packet, i.e. the IP address you want.
(If OTOH your software is not running on the remote machine, you'll need to use some more general-purpose discovery mechanism such as mDNS or LLDP -- hopefully you won't have to do that, though, as it's a good deal more complicated)

Qt5 Bind TCP Socket on Multihomed Network

I am having troubling using the new bind feature of the QTcpSocket class in Qt5. Any help figuring this out would be appreciated.
I have a multihomed server that contains two NICs each with a separate IP address. I have setup routing on the servers so that sending from the source address is sent out of the appropriate NIC regardless of the target remote address. That is, sending from x.x.x.0 goes out over eth0 and x.x.x.1 goes out over eth1 regardless of who the data is being sent to. These NICs are connected via ethernet to long range Wifi links that are then connected to a switch. These wifi links act as a transparent bridge and can rather be seen as two ethernet cables (but they are limited in bandwidth). The switch is then connected to a computer. The goal is to transfer data between the server and the computer, and to use the two wifi links in parallel to increase bandwidth. Although the server is physically a server, the software has the computer running as the software server (as others connect to it). That is, the physical server (software client) opens TCP sockets and attempts to connect to the listening computer (software server).
I use the bind feature of Qt5 to bind one TCP socket to the eth0 IP address and bind another TCP socket to the eth1 IP address. I have verified this works with other programs like PING or file transfer via SCP. See http://qt-project.org/doc/qt-5.0/qtnetwork/qabstractsocket.html#bind
When I call bind the call succeeds and subsequent requests for the local IP address returns the correct value. E.g. socket->bind(ip) returns true and then socket->localAddress() equals ip. However, when I call connectToHost the localAddress is lost when it starts the connection attempt and after connecting it has a different localAddress that is not the one I wanted it to have.
Can anyone shed light into what is going on? I am trying to avoid rewriting the software to reverse the roles of software client / server as these programs are quite big. Thanks for the help.
There is an open bug on this in the Qt project bug tracker.

How to acess COM port of remote system?

I Want to access the COM port present in the remote system from system. Any help would be appreciable.
I am using windows XP in both remote as well as local system.
The com0com project, and especially the com2tcp application should help you.
In conjunction with the Null-modem
emulator (com0com) the com2tcp enables
to use a COM port based applications
to communicate with the TCP/IP based
applications. It also allows
communication with a remote serial
port via the TCP/IP.
Personally, I use SerProxy, which makes that com port looks like telnet:
Serproxy is a multi-threaded proxy program for redirecting network socket connections to/from serial links, in cases where the remote end of the serial link doesn't have a TCP/IP stack (eg an embedded or microcontroller system). The proxy allows other hosts on the network to communicate with the system on the remote end of the serial link.
I also looked into com0com before, but I finally decide not to use it, as it requires a driver installation. Where as serproxy just need to be run. Another nice part is that if the com port is not being "used" remotely, I can still access it locally.
I've used Advanced Virtual COM Port to share a COM port remotely.
On the local PC, it creates a virtual COM port that mirrors the activity of a real COM port on the remote PC. The remote PC can be on a local network or on the Internet. (If on the Internet, you just have to make sure your firewalls allow the particular TCP ports through.)
I tried several programs to share a COM port remotely, but this was the only one I found that also shared the serial hardware handshaking signals. So we picked this one, and it worked great. We used it about 3 years ago, to access a Japanese CDMA modem dev board, sitting in Japan, from Australia.

A Reliable way to Identify a computer by its ip address

I have a network of computers that they will connect to the a server with DHCP, so I don't know what Ip address a computer will get when I connects to the server. If 192.168.0.39 for example is connected to the server can I identify the real computer behinde this ip address? ( I can install an external application on each client in order to send some data to server for example mac address or so... )
If you are responsible for the DHCP server, you can configure it to hand out a specific IP to a specific MAC. Having done that, you can be reasonably confident of that mapping -- it is possible to spoof MACs, so if you are worried about security, you'll need a much more heavy duty approach. If this is a casual application where the risk of that is low, you configure your DHCP server to hand out IPs based on MACs and then make use of those mappings in your application.
You might not even need the IP address. On an Ethernet network, all communication from a computer, whether it's IPv4, IPv6, or even IPX will be labelled with a MAC address that's stable over time and unique per network card.