networking - Setting an IP address for each terminal window - Ask Ubuntu
for project have develop tcp client server connection in c. i've done both files , both working localhost address 127.0.0.1. however, i´d run 2 server simultaneously, 1 127.0.0.1 , other 127.0.0.2 example.
to that, set ip address each terminal window. haven't found how that. i've found information loopback, ip addr add 127.0.0.2 dev lo
, don't know how run each window ip. possible? how?
i know work if had different ports, or if had different server's code changing specified ip 127.0.0.1 on 1 , 127.0.0.2 on other. however, thing is, want know if possible specify 1 each terminal example can use same server code on them. that's simulating connection different computers.
as now, set addr inaddr_any
, connection 127.x.x.x accepted , works. them again, on same port number, need, want run 2 or more server simultaneously, need different ips. , localhost set 127.x.x.x, want narrow down, each terminal receives "part" of localhost address
that's not how ip addresses work. 127.x.x.x addresses resolve same localhost/lo interface. if server listens/"binds" on 127.x.x.x addresses client running on same box can connect it. e.g. other clients on same network won't able connect it.
you have specify in server's c code ip address (and port) listen on, or can pass ip in server program argument. starting same code different terminals makes no difference.
if want start running both servers simultaneously have run them on different tcp port numbers. (which whole purpose of ports)
Comments
Post a Comment