ZeroMQ (0MQ) basic issue re connecting or binding to sockets - sockets

I'm using ZeroMQ on Windows, using C#, and am confused by a very basic networking question. I set up simplistic sample programs, one to PUBlish messages, the others use a SUB socket to receive them (the SUBscriber programs).
Works fine when both are on the same box. I used endpoint tcp://127.0.0.1:5000
As the next step, I put the SUBscriber program on a separate virtual machine (VM), to simulate using separate computers. I ran ipconfig to get it's IP address (on the guest os), 192.168.92.136
The host os has several network interfaces, one of which is the VMware Network Adapter VMnet1, with IP 192.168.92.1
On the host os, I ran the PUB program and connected the socket to 192.168.92.136, the IP address of the guest os.
On the guest os, I ran the SUB program and connected the socket to the IP of the host os. Did not work.
Then I changed the SUB program on the guest os to make it connect it to it's own IP address, ie that of the guest os - 192.168.92.136. Now it works!
Question: Why? I'm confused. But in a way it sort of makes sense: if that socket is for a service that attends to various clients that dynamically come and go, it doesn't know the IP address of each client. Therefore what the heck do you specify as the IP address for the SUB socket?! So connecting it to it's own host IP address does solve that concern. But the ZeroMQ Guide doesn't say this anywhere!
A related question is: if your host has multiple network interfaces, and each has it's own IP address, then if you connect your socket to some other host using the IP address of that other host - do you not need to specify which of those network interfaces you want to connect through? If so, how?
Incidentally, only one subscriber program seems to be able to connect at a time. The 2nd program to attempt to connect to it's SUB socket to the local IP address always gets a "Address is in use" error-message. I'm trying to make progress in small steps and learn this as I go.
Thanks for any help or advice.
James Hurst, JamesH at Designforge dot com

Related

How to know which interface is connected to particular machine?

I have a server with a lot of interfaces, and only one interface is assigned IP address, this interface is kept for management.
but other interfaces are connected to the other server.
I want to know which interface is actually connected to the outside server.
Here, I tried to ping to the machine IP with particular interface ping -I eth1 x.x.x.x.
But not able to ping with the interface even though I know this is connected to the server.
All the packet is only going via the management eth0.
Is there a better way to find out which interface is connected to a particular machine?
I know the machine IP address
I am using ubuntu 18.04

How to create a virtual network interface on a remote machine bridge to an interface on a local machine?

I have a local Linux machine (L), with a network interface (eth0) connected to (currently) only one device (D).
L/eth0 only has an ipv6 link local address.
D also only has an ipv6 link local address.
Client software on L discovers D's link local address by sending a custom multicast packet over eth0. The response contain the device link local address as well as some configuration information. From there it communicates with the device using various UDP or TCP port.
My goal is to be able to use the device from a remote machine (R). The remote machine being most likely a Linux docker container running on some host - although it could be a native macOS or other.
That means running both the discovery protocol and communicate with the device. I definitely cannot modify software on the device, and cannot modify most of the client software running on the local Linux or remote machine (Limited modification could possibly be requested)
My idea was to somehow create a virtual interface on the remote machine, that would remotely be bridged to the the local machine, so that the multicast discovery works from the remote, and so that I can just connect to D link local address from the remote.
I'm not sure which tool(s) I should be using.
I'm googling various things about VPN and tunnel, TUN/TAP interfaces, bridges, VETH, VLAN, etc... but I'm having trouble connecting the dots here... I have no budget for this, so I'm looking for open source tools, or just something I can cobble up together with common tools.
Thanks

How does a client socket application identify the server application on the same host computer

I have been trying to learn socket programming in C++ and got some progress for the basics. But I understood that basics are not fundamentals.
One of those fundamentals is about the question which is stated in the title. Lets say I have two separate applications running on the same computer. One of them has a server socket and the other one has a client.
When the server gets an IP address automatically, how can client find the server? Do I have to assign an IP address that is known by the client? In that case, maybe that IP address is not available on the network.
Or can client find and connect to the server by sone kind of name or id?
Have the server bind to all interfaces and have the client lookup 'localhost' by name; it's resolved locally, (ie. no external DNS service required), to an IP address stored in a 'hosts' file, and is set by default to 127.0.0.1
Google 'hosts file'
The IP address of any server in the same host is 127.0.0.1 unless the server has bound to a specific, different IP address. As #MartinJames points out, you can use 'localhost' as the hostname for that, except on certain broken Linux distributions.

Communicating between networks using sockets

I have a question about network connections among computers.
I've made some applications where messages pass through the Internet (via sockets) to make a connection between two devices. However, a strong condition is that two devices must be connected to the same network.
Can anyone give me a trick how to create a communication using sockets between two computers even if they are connected to different netwkorks?
Thank you in advance.
Here is a great tutorial on how to use sockets and general networking
(in java) http://www.thenewboston.org/watch.php?cat=25&number=38
In order to communicate between two diffrent networks over the internet, you will need to do something called port forwarding. What that does is that when your public IP of your network receives a packet with a spesific port number. The router knows where to send that packet to which local IP.
If you dont port forward and receive some data. The router doesent know where to send the packet. Therefore it discards it, which means others wont be able to connect to you.
You will only need to port forward the network with your server (using the example i linked). How you do that is by logging in to your router, and say that a port which the server uses gets forwarded to the IP of the PC hosting the server.
On the other network (client) you will need to change the IP address of which the client shall connect to. That IP address needs to be your public IP of your server's network. You can find that by connecting to the server's network and go to: http://www.whatsmyip.org/ . Keep in mind that public IP addresses may change over time.
Hope this helped!
-Kad

How does communication occur in java through TCP sockets on the same machine

I have two servers, written in Java, that communicate through sockets and TCP. The servers are both on the same Linux machine. If the servers were on different machines then data would have to go through network adapters and network cables, but since the servers are on the same machine how does the OS actually move data efficiently form one server to the other.
Generally, the messages will be sent over the loopback interface:
In TCP/IP a loopback device is a virtual network interface implemented in software only and not connected to any hardware, but which is fully integrated into the computer system's internal network infrastructure. Any traffic that a computer program sends to the loopback interface is immediately received on the same interface.
However, you can manage to configure your situation so that, for example, the server is referred to via an external IP address so that messages actually go out over the network before being routed back to the same machine.
If two programs are using TCP/IP to communicate on the same machine, they are probably connected through the loopback interface