The first 4 bytes of every message sent over the bitcoin network protocol contain a "magic number," which identifies it as Bitcoin or some other chain. Bitcoin's magic number for mainnet is 0xD9B4BEF9. Anyone forking the code to implement a different chain should use a new magic number to distinguish it from Bitcoin.
You could technically have multiple chains with the same piece of software if they handle messages based on the magic number, but it's more likely that you would run them as independent pieces of software, in which case, you will use a different listening port for the software to receive incoming connections. (TCP does not allow multiple software to listen on the same port by regular means). Each blockchain would know which port to connect to on your machine because it would've been advertised via gossip or DNS.