For my project I have to develop a TCP client server connection in c. I've done both files and they are both working with the localhost address 127.0.0.1. However, I´d like to run two server simultaneously, one as 127.0.0.1 and the other as 127.0.0.2 for example.
To do that, I would like to set an IP address for each terminal window. I haven't found how to do that. I've found some information about loopback, ip addr add 127.0.0.2 dev lo
, but don't know how to run each window with an IP. Is that possible? How?
I know it would work if I had different ports, or if I had different server's code only changing the specified IP as 127.0.0.1 on one and 127.0.0.2 on the other. However, the thing is, I want to know if it is possible to specify one for each terminal for example so I can use the same server code on them. That's for simulating connection to different computers.
As for now, I set the addr as INADDR_ANY
, so any connection 127.X.X.X is accepted and works. But them again, on the same port number, which is what I need, I want to run 2 or more server simultaneously, so I need different IPs. And as localhost is set as 127.x.x.x, I want to narrow it down, so each terminal receives "part" of the localhost address