sure you can use host name instead of ip address to connect.
if you look at source code for client.connect, your dns lookup failed
int EthernetClient::connect(const char* host, uint16_t port) {
// Look up the host first
int ret = 0;
DNSClient dns;
IPAddress remote_addr;
dns.begin(Ethernet.dnsServerIP());
ret = dns.getHostByName(host, remote_addr);
if (ret == 1) {
return connect(remote_addr, port);
} else {
return ret;
}
}
if you used dhcp, the ethernet library will use the dns server returned by your dhcp server.
if you used static ip and did not explicitly set the dns server, it will use the same ip as your static ip but replace the last number with 1 (which usually defaults to the router/gateway).