Can't connect sockets when the endpoint address is not an IP Address

Connecting or binding to "tcp://127.0.0.1:5001" works, but "tcp://localhost:5001" fails.