This is for a school project so I need to use UDP Broadcast.
I am building a P2P app that uses only port 5000 over UDP. I need to send a discovery broadcast packet to all clients in my network.
Normally the app will be used over Hamachi but for the purpose of developing I would like to use the simplest fastest network environment so I would like to test multiple instances locally.
I discovered that it is possible to use 127.0.0.1 127.0.0.2 etc as IPs for my local instance. (Actually tested with ips from 1 to 6 and sending messages at random to each other)
I now need to use the SAME port 5000 but do a broadcast UDP
When I invoke ifconfig on the loopback interface I do not see the BROADCAST option.
Since apparently it is impossible to add the BROADCAST option to the loopback interface, what is the easiest way to have:
1 ip address per instance
same port
running locally
Should I consider using Docker or VM or some network simulator for this purpose?
If you only want to broadcast to all clients, maybe multicast is enough for you. And this can fullfill all the three need you mention. Here is the definition, and here is a little example may help you.
Related
I'm working on a simple Swift app where one user can find other machines on a local network which are running an instance of my app and then send data to that machine using TCP sockets.
My question is how to find IP addresses of devices on same network which are running an instance of my app (cross-platform)?
I was thinking about listing all devices on local network and then
checking whether they have opened specific port (the port my app is
using)?
I also found that Apple provides service called Bonjour which could make my process discoverable. I'm not sure if this solution is good for cross-platform communication.
Apart of Mac-related stuff and high-level solutions (I believe keywords "network service discovery" will bring you to them), there are a couple of things that will work for a local network:
I Have a server that clients should report to. Some short hello-like UDP message and a timeout mechanism will be sufficient to keep a list of available clients in the network.
II Use IP or UDP multicast groups to notify others that a client has just connected to the network. Send a message to a multicast group and listen to this group to build a list of clients.
However, broadcasts and multicasts won't be transmitted through a router. So if your network is large enough only neighbouring clients will hear your notification. In order to overcome it,
III DHCP servers can be configured to provide custom data to clients via unassigned DHCP options. Large networks have usually such server. You probably can use it to send out a list of clients, but I'm not sure about this.
I am trying to connect over Linux. My device is connected to two LANs (say eth0 and eth1) with different networks.
Both networks are connected to internet. I want my client program to be able to use eth1 even though my eth0 is the default interface.
There is an option setsockopt (SO_BINDTODEVICE) to bind to a specific interface but requires root priviledges which is not possible.
Binding to IP address of eth1 is not helping either. Please suggest is there any other way through socket APIs to link the connection with the interface. i.e. my client program will always usse eth1 source IP and interface to connect to the internet whereas all other programs will continue to use eth0 as ususal.
I investigated and appears changes in routing table can help in this but trying to avoid being risky to make system unstable as that is applied to every other programs too.
Thanks in advance.
Kris
I have heard that sockets are used for all sorts of streaming between applications to send and receive data.
I have always thought and even read from articles that aim to give a "general sense" that sockets are used to create connections over networks.
However recently I saw that sockets are also used for local streaming/connections between apps which are not over a network.
My question;
How are sockets used for connections/streaming NOT over a network between apps?
If the applications are on the same machine then you can use the localhost or loopback address 127.0.0.1 as the IP address of the socket and any port number > 1024 in both applications and then they can communicate over this connection .
Also, if you want to use the socket approach and on linux, AF_UNIX is better than inet socket as they avoid some level of inet specific tasks like routing/adding-removing ip and transport headers, etc
I am in the process of developing a peer to peer app,
I am a bit confused by the following scenario:
Lets say my application will use an outgoing port 1863 - which is also used for msn messenger(if this is not the port lets assume it is)
Now, client executes my app and connects to my server at port 1863.
I am a bit confused if this is going to produce any problems.
I know that 2 apps can use same port for outgoing communication. But what happens to the data coming back?
Also, does my client need to open port for my app to run correctly??
I know that 2 apps can use same port for outgoing communication. But
what happens to the data coming back?
That's exactly the problem the source port solves. The peer can always differentiate between 2 connections based on it. When it sends replies, what was the source port now becomes the destination port allowing the original receiver to correctly pass data to the rightful processes.
I an writing a small application that needs to connect through one of multiple network interfaces on the machine. The interface is not the "default" one (the one with the default route). Is it possible to bind an outbound TCP socket directly to a specific interface?
Here is an example:
eth0: 192.168.1.10, gateway 192.168.1.1
eth1: 192.168.2.10, gateway 192.168.2.1
default gateway: 192.168.1.1
(both interfaces can reach the Internet through different external IPs)
Now, I want my application to use eth1 to connect to an external server, even if the system is configured to use eth0 for external traffic.
(The question is probably trivial, but I just wanted to know if it is possible at all before spending time on it)
Currently, I am using Python with Twisted, but if I have to use BSD sockets then so be it.
From: http://linux.about.com/od/commands/l/blcmdl7_socket.htm
SO_DONTROUTE - Don't send via a gateway, only send to directly connected hosts. The same effect can be achieved by setting the MSG_DONTROUTE flag on a socket send(2) operation. Expects an integer boolean flag.